skip to Main Content

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


  1. 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
    
    Login or Signup to reply.
  2. if you are facing following error when running docker –

    docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
    See 'docker run --help'
    

    or

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

    Run following commands

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

    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

    $ ps -p 1 -o comm=
    init 
    

    so now you check again the status using

    $ sudo service docker status
     * Docker is not running
    

    you can start docker using the following command

    sudo service docker start
     * Starting Docker: docker
    

    for more detail pls refer following link
    https://linuxhandbook.com/system-has-not-been-booted-with-systemd/

    Systemd command Sysvinit command
    systemctl start service_name service service_name start
    systemctl stop service_name service service_name stop
    systemctl restart service_name service service_name restart
    systemctl status service_name service service_name status
    systemctl enable service_name chkconfig service_name on
    systemctl disable service_name chkconfig service_name off
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search