我在试着让詹金斯去管理Docker
.
到目前为止
我可以在没有詹金斯的情况下在docker本地运行systemd
. 以下是在没有jenkins的情况下在本地运行它的步骤:
# pull unop/fedora-systemd and create and run the container for it
sudo docker run --cap-add=SYS_ADMIN -e container=docker --tmpfs /run --tmpfs /tmp -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t -i unop/fedora-systemd
# on a different terminal window, I can:
# get the container id of the "unop/fedora-systemd" image
sudo docker ps
# then exec bash on it
sudo docker container exec -t -i a98aa2bcd19e bash # where a98aa2bcd19e is the container id found above
# once inside the container, I can run systemd without any problems. examples:
systemctl status
systemctl start dbus.service
systemctl status dbus.service
上面的工作是本地的,我可以在docker容器中运行systemd。
我得到的问题是当我尝试同样的事情,但在詹金斯内部。
我试过几次调整Jenkinsfile,但我以前的尝试似乎没有奏效。我总是得到一个
在詹金斯手下跑步时出错
与此类似:
+ systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
这是我最新的
詹金斯档案
我已经试过了
pipeline {
agent {
docker {
image 'unop/fedora-systemd'
args '--cap-add=SYS_ADMIN -e container=docker --tmpfs /run --tmpfs /tmp -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t -i'
}
}
stages {
stage('test') {
steps {
sh "echo hello world"
sh "systemctl status"
sh "systemctl start dbus.service"
sh "systemctl dbus.service"
}
}
}
}
在Jenkinsfile的前几次迭代中,我试图替换
-cap-add=SYS_ADMIN -e container=docker
对于
--privileged
,但那没用,我还是犯了同样的错误
有人知道我怎样才能让它工作吗?为什么上面的工作是本地的,而不是詹金斯?我错过了什么?
注意:Jenkins版本:2.150.2这是
停靠文件
使用人
unop/fedora系统
FROM fedora:rawhide
MAINTAINER http://fedoraproject.org/wiki/Cloud
ENV container docker
RUN dnf -y update && dnf clean all
RUN dnf -y install systemd && dnf clean all && \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup", "/tmp", "/run" ]
CMD ["/usr/sbin/init"]
PS:我见过
related question
,但他们的要求不同