【问题标题】:Docker with systemctl带有 systemctl 的 Docker
【发布时间】:2021-07-22 10:11:04
【问题描述】:

我创建了一个基于 Ubuntu 20.04 的 dockerfile,它更改 .bashrc 并从 github 克隆存储库并开始安装。 (在存储库中存在安装程序的文件 server_install.sh。)

Dockerfile:

FROM ubuntu:20.04  
USER root  
LABEL maintainer="zarooba"  
ENV TZ=Europe/Warsaw  
ENV DEBIAN_FRONTEND=noninteractive   
ADD aamks_bashrc.txt /root  
RUN touch /root/.bashrc && cat /root/aamks_bashrc.txt >> /root/.bashrc  
RUN apt-get update  
RUN apt-get install -y python3  
RUN apt-get install -y git  
WORKDIR /usr/local  
RUN git clone https://github.com/aamks/aamks.git  
RUN ["chmod", "+x", "/usr/local/aamks/installer/server_install.sh"]  
RUN apt-get update -y && \  
    apt-get -y install sudo && \  
    apt-get install -y systemd   
CMD /usr/local/aamks/installer/server_install.sh 

安装开始,一切正常,但在安装过程中的某个时刻出现了错误:

Bug with systemctl: System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

systemctl 已按照 dokefile 中的说明进行安装。我不知道如何摆脱这个错误。

包含 systemctl 的文件 server_install.sh 的行:

sudo systemctl daemon-reload
sudo systemctl restart gearman-job-server.service

【问题讨论】:

  • 在大多数情况下,systemctl 在 Docker 中根本不起作用。我会避免在容器中安装 Systemd(它非常重量级且具有侵入性),以及 git(关于凭据和更新存在一些操作问题)和 sudo(在 Docker 中是不必要的),以及大多数运行容器的路径都没有使用.bashrc 文件。你能不使用安装程序手动安装软件,并将CMD设置为前台进程运行(不使用systemctl或任何类型的init系统)?
  • 感谢您的回复。我纠正了你所建议的事情,它奏效了。它应该是用安装程序安装的,但这并不是所有这些中最大的问题。

标签: docker dockerfile systemctl


【解决方案1】:

所有 docker RUN 脚本都将在您无法控制 PID 1 的容器中启动。它实际上是您尝试在其中执行的脚本。如果它是另一个服务,那么在每个 stp 中启动/停止进程有时会很有帮助。

RUN dbctl start ; execdb -c "CREATE USER"; dbctl stop

有一个解决方法是使用docker-systemctl-replacement 脚本拦截 systemctl 执行,并且还可以根据需要启动/停止所需的服务。这允许您在容器中运行面向 VM 的“server_install”(无需修补)

【讨论】:

  • 谢谢。我需要在 server_install 中重新启动服务,并将 systemctl 替换为 service restart。它奏效了。
猜你喜欢
  • 1970-01-01
  • 2019-03-15
  • 1970-01-01
  • 2019-03-06
  • 2022-01-23
  • 1970-01-01
  • 2023-01-28
  • 2018-09-05
相关资源
最近更新 更多