我正在尝试启动一个以 systemd 为初始化进程的 docker 容器,以便可以从该容器运行多个服务,但是我收到以下奇怪的错误:
当我运行 top 时,Systemd 被列为 PID 1,但我通过 systemctl 启用的服务均未运行,并且尝试使用 systemctl status 给它们提供了system has not been booted with systemd as init process (PID 1)
这是我的docker文件:
FROM ubuntu:20.04
ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/# deb/deb/g' /etc/apt/sources.list
RUN apt-get update \
&& apt-get install -y systemd systemd-sysv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN cd /lib/systemd/system/sysinit.target.wants/ \
&& ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/basic.target.wants/* \
/lib/systemd/system/anaconda.target.wants/* \
/lib/systemd/system/plymouth* \
/lib/systemd/system/systemd-update-utmp*
...assorted aptget installs...
ENV LOCAL="yes"
...assorted utils scripts...
RUN useradd --create-home fractal \
&& usermod -aG sudo fractal \
&& echo 'fractal:password1234567.' | chpasswd
...assorted utils scripts...
ADD bootstrap.sh /home/fractal
ADD entry.sh /home/fractal
ADD fractal-input.rules home/fractal
RUN chmod +x /home/fractal/bootstrap.sh \
&& chown -v -R fractal:fractal /home/fractal
RUN chown root:root /run/user
RUN chmod +x /home/fractal/entry.sh
...adding assorted services...
VOLUME [ "/sys/fs/cgroup" ]
RUN systemctl set-default multi-user.target
ENV init /lib/systemd/systemd
....assorted services enabled....
CMD ["/lib/systemd/systemd"]
答案1
如果不做太多努力,你就无法在 Docker 容器中使用 systemd。大多数人使用类似主管反而。