我正在使用基于Alpine的映像,其中包含Jenkins和Docker。这样,我将能够创建运行Docker命令的作业(至少这是目标)
我正在以jenkins
用户身份运行Jenkins,但是我将该用户添加到了根组中(所以我想像是以root身份运行Jenkins)。
当我尝试运行docker
命令时,例如出现docker ps
时,出现以下错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
当我尝试找到docker.sock
时,它不存在,并且据我所知,该文件仅在docker运行时才存在。因此,我尝试运行sudo dockerd
,出现以下错误:
[configuration-as-code] Running shell script
+ sudo dockerd
time="2018-06-28T13:00:33.997879668Z" level=warning msg="Could not set daemon root propagation to shared, this is not generally critical but may cause some functionality to not work or fallback to less desirable behavior" dir=/var/lib/docker error="operation not permitted"
time="2018-06-28T13:00:34.008211600Z" level=info msg="libcontainerd: started new docker-containerd process" pid=1844
time="2018-06-28T13:00:34Z" level=info msg="starting containerd" module=containerd revision=9584b2309e5be604504d4a8ff7ef5def5b42e9a0 version=v3.7.0-117-g9584b2309e
time="2018-06-28T13:00:34Z" level=info msg="setting subreaper..." module=containerd
time="2018-06-28T13:00:34Z" level=info msg="changing OOM score to -500" module=containerd
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.content.v1.content"..." module=containerd type=io.containerd.content.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.snapshotter.v1.btrfs"..." module=containerd type=io.containerd.snapshotter.v1
time="2018-06-28T13:00:34Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.btrfs" error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter" module=containerd
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.snapshotter.v1.overlayfs"..." module=containerd type=io.containerd.snapshotter.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.metadata.v1.bolt"..." module=containerd type=io.containerd.metadata.v1
time="2018-06-28T13:00:34Z" level=warning msg="could not use snapshotter btrfs in metadata plugin" error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter" module="containerd/io.containerd.metadata.v1.bolt"
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.differ.v1.walking"..." module=containerd type=io.containerd.differ.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.gc.v1.scheduler"..." module=containerd type=io.containerd.gc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.containers"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.content"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.diff"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.events"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.healthcheck"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.images"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.leases"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.namespaces"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.snapshots"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.monitor.v1.cgroups"..." module=containerd type=io.containerd.monitor.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.runtime.v1.linux"..." module=containerd type=io.containerd.runtime.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.tasks"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.version"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg="loading plugin "io.containerd.grpc.v1.introspection"..." module=containerd type=io.containerd.grpc.v1
time="2018-06-28T13:00:34Z" level=info msg=serving... address="/var/run/docker/containerd/docker-containerd-debug.sock" module="containerd/debug"
time="2018-06-28T13:00:34Z" level=info msg=serving... address="/var/run/docker/containerd/docker-containerd.sock" module="containerd/grpc"
time="2018-06-28T13:00:34Z" level=info msg="containerd successfully booted in 0.034450s" module=containerd
Error starting daemon: couldn't create plugin manager: error setting plugin manager root to private: operation not permitted
我的docker撰写文件:
version: '3'
services:
master:
build: .
restart: always
volumes:
- /var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /var/run/docker.sock:/var/jenkins_home/docker.sock
- /usr/local/bin/docker:/usr/bin/docker
ports:
- "50000:50000"
- "8080:8080"
与root
一起运行Jenkins时,输出的结果完全相同。
任何人都可以帮助如何在Jenkins中运行docker命令吗?