I use docker with centos 8.
How can i use systemctl command in dockerfile please ?
When i install an app it needs systemctl.
I have an error:
System has not been booted with systemd as init system (PID 1). Can’t
operate. Failed to connect to bus: Host is down
I build docker like this:
docker build -t myapp:11 .
Same when i try in container:
docker run -it --privileged app:11 /bin/bash
Thank you.
docker build -t nuance:11 .
docker run -it –cap-add=NET_ADMIN nuance:11 /bin/bash
# syntax=docker/dockerfile:1
FROM centos:latest
USER root
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum -y update &&
yum clean all
RUN yum -y install
java-11-openjdk-devel
perl-Data-Dumper
redhat-lsb-core.x86_64
glibc.x86_64
glibc.i686
libstdc++.x86_64
libstdc++.i686
openssl
libgcc
libgcc.i686
libaio.x86_64
libaio.i686
libnsl.i686
ncurses-libs
httpd.x86_64
unzip
-x postfix
-x mariadb-libs
zlib.i686
zlib.x86_64
WORKDIR /tmp
COPY Nuance_Speech_Suite-11.0.10-x86_64-linux.tgz ./Nuance_Speech_Suite-11.0.10-x86_64-linux.tgz
COPY NRec-fr-FR-10.0.0-10.1.0.i686-linux.tar.gz ./languages/NRec-fr-FR-10.0.0-10.1.0.i686-linux.tar.gz
COPY NVE_fr_FR_audrey-ml_xpremium-2.1.0_linux.zip ./languages/NVE_fr_FR_audrey-ml_xpremium-2.1.0_linux.zip
COPY NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-1_linux.zip ./languages/NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-1_linux.zip
COPY NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-2_linux.zip ./languages/NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-2_linux.zip
COPY nuance.lic ./nuance.lic
RUN tar -zxf Nuance_Speech_Suite-11.0.10-x86_64-linux.tgz
RUN tar -zxf languages/NRec-fr-FR-10.0.0-10.1.0.i686-linux.tar.gz
RUN unzip languages/NVE_fr_FR_audrey-ml_xpremium-2.1.0_linux.zip
RUN unzip languages/NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-1_linux.zip
RUN unzip languages/NRec-fr-FR-10.0.0-10.1.0-CumulativePatch-2_linux.zip
WORKDIR /tmp/Nuance_Speech_Suite-11.0.10
RUN ./setup.sh -s -f "/tmp/nuance.lic" -j "/usr/lib/jvm/java-11-openjdk" -V "/tmp/languages" -I "NLM,NSS"
last lines of log
2022-12-16 09:22:11 setup.sh: info: Restarting the Nuance License Manager service
2022-12-16 09:22:11 setup.sh: info: starting command ‘systemctl restart nuance-licmgr’; output sent to log
System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down
2022-12-16 09:22:11 setup.sh: info: Command ‘systemctl restart nuance-licmgr’ returned 1
2022-12-16 09:22:11 setup.sh: error: install_postprocessing_nlm_startservices() failed to start services
2022-12-16 09:22:11 setup.sh: info: skipping invocation of install_postprocessing_nms() due to previous post processing errors
2022-12-16 09:22:11 setup.sh: info: Skipping install_execute_installsuite due to previous errors
2
Answers
You can’t run
systemctl
in a Dockerfile at all. More broadly, commands likesystemctl
orservice
don’t work well in Docker, and you should restructure your container to avoid them.For
systemctl
more specifically, it tries to connect to thesystemd
daemon. In a Dockerfile, eachRUN
step occurs in a new container, and like other containers, that container only runs the oneRUN
command; it does not runsystemd
or any other typical Linux daemons. Furthermore, at the end of theRUN
line, the filesystem is persisted but any other changes are lost, so even if yousystemctl start
something successfully, the image won’t contain a running process.More generally I’d recommend avoiding
systemd
in Docker. A minimal init system liketini
can be a good idea for some problems like reaping zombie processes; if you must run multiple processes in one container and really can’t refactor it thensupervisord
can fill this need. A typicalsystemd
installation will want to configure kernel parameters, start terminal logins, mount filesystems, and configure the network, all of which are basically impossible in Docker; it will capture the main process’s stdout sodocker logs
doesn’t work.Aim for your container to only have one process. Don’t run an init system at all if you don’t need to. Don’t try to "start a service", just run the program you’re trying to build in the foreground as the one thing the container does.
if you are facing following error when running docker –
or
Run following commands
The reason is that you are trying to use systemd command to manage services on Linux but your system doesn’t use systemd and (most likely) using the classic SysV init (sysvinit) system.
run following command to confirm if its above case
so now you check again the status using
you can start docker using the following command
for more detail pls refer following link
https://linuxhandbook.com/system-has-not-been-booted-with-systemd/