Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"systemctl" command doesn't work on centos with docker

Tags:

docker

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

like image 295
jeyGey Avatar asked May 13 '26 11:05

jeyGey


1 Answers

You can't run systemctl in a Dockerfile at all. More broadly, commands like systemctl or service don't work well in Docker, and you should restructure your container to avoid them.

For systemctl more specifically, it tries to connect to the systemd daemon. In a Dockerfile, each RUN step occurs in a new container, and like other containers, that container only runs the one RUN command; it does not run systemd or any other typical Linux daemons. Furthermore, at the end of the RUN line, the filesystem is persisted but any other changes are lost, so even if you systemctl start something successfully, the image won't contain a running process.

More generally I'd recommend avoiding systemd in Docker. A minimal init system like tini 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 then supervisord can fill this need. A typical systemd 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 so docker 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.

FROM some-base-image
RUN a command to install the software
CMD the_program
# with no `systemctl` anywhere
like image 59
David Maze Avatar answered May 16 '26 14:05

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!