The command “systemctl status” is not working. It never has. My container is on CentOS 7. When I issue “systemctl status” I get results “Failed to get D-Bus connection: operation not permitted.”
I then looked into upgrading systemd. I removed the /etc/yum/protected.d/system.conf file. I then used yum remove systemd. I see that systemd version 219-19.el7_2.4 has been installed. I choose “N” to not actually remove systemd. I then installed systemd-libs-219-19.el7_2.7.x86_64.rpm. I then installed systemd version 2.7. I then used yum remove systemd just to determine the version. I see that systemd version 219-19.el7_2.7 is installed. I choose “NO” to abort the removal. systemctl status still does not work. I get the same error: “Failed to get D-Bus connection: operation not permitted.”
I tried creating a Docker container with the -privileged flag. When I used the “-p 80:80” option, the Docker run command failed. When I left out the “-p 80:80” option in my Docker run command, the new container had the same problem.
I tried creating a Docker container with the -privileged flag. When I used the “-p 80:80” option, the Docker run command failed to create a new container. When I left out the “-p 80:80” option in my Docker run command, the new container had the same problem.
I created a Docker container with a “docker run” … “-v /sys/fs/cgroup:/sys/fs/cgroup:ro” option. But I had the same problem.
I expect “systemctl status” to work. I don’t know if the problem is with how I created the Docker container. Reinstalling (or upgrading) systemd did not work. What should I do to get “systemctl status” to work in a Docker container?
Normally when you run a container you aren’t running an init system. systemctl is a process that communicates with systemd over dbus. If you aren’t running dbus or systemd, I would expect systemctl to fail.
What is the pid1 of your docker container? It should reflect the entrypoint and command that were used to launch the container.
For example, if I do the following, my pid1 would be bash:
$ docker run --rm -it centos:7 bash
[root@180c9f6866f1 /]# ps faux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.7 0.1 11756 2856 ? Ss 03:01 0:00 bash
root 15 0.0 0.1 47424 3300 ? R+ 03:02 0:00 ps faux
Since only bash and ps faux are running in the container, there would be nothing for systemctl to communicate with.
Following @kornzysiek update, I’ve tried it & when i execute it, the init phase gets hung and doesn’t respond. Any directions from here ? I’ve to open another terminal & stop the container to get this terminated.
Set hostname to <052069cdd742>.
Initializing machine ID from random generator.
[ OK ] Reached target Swap.
[ OK ] Reached target Paths.
[ OK ] Reached target Local File Systems.
[ OK ] Created slice Root Slice.
[ OK ] Listening on Journal Socket.
[ OK ] Listening on Delayed Shutdown Socket.
[ OK ] Created slice System Slice.
Starting Create Volatile Files and Directories…
[ OK ] Reached target Slices.
Starting Journal Service…
[ OK ] Started Create Volatile Files and Directories.
[ INFO ] Update UTMP about System Boot/Shutdown is not active.
[DEPEND] Dependency failed for Update UTMP about System Runlevel Changes.
Job systemd-update-utmp-runlevel.service/start failed with result ‘dependency’.
[ OK ] Started Journal Service.
[ OK ] Reached target System Initialization.
[ OK ] Listening on D-Bus System Message Bus Socket.
[ OK ] Reached target Sockets.
[ OK ] Reached target Basic System.
[ OK ] Reached target Multi-User System.
[ OK ] Reached target Timers.
You can’t do it without giving the container almost unlimited power over the host system and the ability to break out of the container space, and if you do manage to start systemd it will break things like the host cgroup settings (and to make things worse you’ll have two systemds trying to manage host-global things).
As far as Docker is concerned, in your Dockerfile, you should pretend commands like systemctl and initctl and service and the /etc/init.d tree just don’t exist. Even if you can run them they won’t do what you expect.
nope they can’t suggest you… docker is terrible if you actually need your container to act as a server that needs to do more then 1 thing… just implementing something simple as a autorenew service for an ssl cerficate requires you to invent your own workarounds…
I am working on creating a Docker Image with an existing open source App that doesn’t currently have an official image. In existing images they use the actual init.d service which is also not recommended. Following the install instructions for Ubuntu, the service is started using systemctl, if this is not the correct method what is the correct method for handling applications that are typically started using systemctl?
Sorry but I’m new to Docker. Can you explain in more detail where that file goes.
I do web development, I know something about Linux, I work with Centos, but I can’t get a container with Centos 7 to work in Window Docker (work systemctl, mysq, apache, ssh, rsync,) Thanks in advance
I thing this is the best and I had configured with this dockerfile and absolutely work for me.
MAINTAINER “MD aakir” firstname.lastname@example.org
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all;
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done);
RUN rm -rf /lib/systemd/system/multi-user.target.wants/;
RUN rm -rf /etc/systemd/system/.wants/;
RUN rm -rf /lib/systemd/system/local-fs.target.wants/;
RUN rm -rf /lib/systemd/system/sockets.target.wants/udev;
RUN rm -rf /lib/systemd/system/sockets.target.wants/initctl;
RUN rm -rf /lib/systemd/system/basic.target.wants/;
RUN rm -rf /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ “/sys/fs/cgroup” ]
Hi @kornzysiek ,
I just created a ubuntu instance in the docker and installed “Redis” manually by using the below link.
When I am working with "sudo systemctl start redis " getting an error. Is there any alternative way to start the Redis…?