社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

无法在docker中运行systemd,而docker正在jenkins中运行

Unglued • 6 年前 • 2252 次点击  

我在试着让詹金斯去管理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 ,但他们的要求不同

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52837
文章 [ 1 ]  |  最新文章 6 年前
Guido U. Draheim
Reply   •   1 楼
Guido U. Draheim    7 年前

我不知道有关的问题。让我再次指出,如果一个systemd控制的容器只是要在其中运行多个服务,则不需要在其中运行systemd守护进程。简单地覆盖 /usr/bin/systemctl 与 docker-systemctl-replacement 脚本。然后去登记 CMD ["/usr/bin/systemctl"] 作为容器的初始进程。

就这样。现在您可以从操作系统运行任何systemctl start进程。它的工作原理是,即使使用ansible/puppet脚本进行配置也完全没有问题。具体来说,我用它来为Jenkins映像提供操作系统,开发人员希望以此为基础。不需要特权模式。