I downloaded the centos 7 docker image from docker hub. When I try to enable sshd on the server, it does not allow me to enable ssh service.

Below are the steps to replicate my issue:

docker pull centos
docker run -i -d --name testSSH centos /bin/bash
docker exec -it testSSH /bin/bash

Once inside the centos box, I executed the following commands:

yum install openssh-server
ssh-keygen -t rsa
yum install -y initscripts
service start sshd
service sshd start

I get this error message now:

[root@f9e4d1efcfd9 /]# service sshd start
Redirecting to /bin/systemctl start sshd.service
Failed to get D-Bus connection: Operation not permitted

I have used physical centos machines, and the same command works perfectly.

  • 2
    You'll probably need to activate systemd, as per the instructions under the 'Systemd integration' heading: hub.docker.com/_/centos
    – Haxiel
    Dec 24, 2018 at 6:24
  • I will be really glad if down-voters kindly explain why they down-voted a question. Dec 24, 2018 at 6:58
  • Thanks @Haxiel I followed the steps as mentioned in the link you provided. I referred to unix.stackexchange.com/questions/276340/… , but I have the same error. Dec 24, 2018 at 8:03
  • 1
    Perhaps you can add some information about what you're trying to accomplish? Docker is something of a process isolation framework, and sshd doesn't really fit into that paradigm.
    – Haxiel
    Dec 24, 2018 at 8:21
  • 1
    I need to install a machine that contains greenplum database and my application on the same machine. The installation for database needs ssh localhost to work. I am trying to activate sshd for that. My laptop is a ubuntu 16.04 machine Dec 24, 2018 at 8:35

1 Answer 1


The current official Docker image for CentOS does contain systemd, but it is inactive by default. This is documented at the Docker Hub page for the CentOS image.

Systemd is now included in both the centos:7 and centos:latest base containers, but it is not active by default. In order to use systemd, you will need to include text similar to the example Dockerfile below:

The sample Dockerfile provided is as follows:

FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

By removing these files, systemd is prevented from starting several services during container startup. This approach results in a bare-bones, yet functional systemd inside the container.

Running a container from this image also requires a specific option to mount the cgroup volume:

$ docker run -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd-app

The -v option bind mounts the /sys/fs/cgroup directory from the host to the container in a read-only fashion.

It is also noted that on Ubuntu hosts, an additional option may be required for the container to work correctly:

$ docker run -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /tmp/$(mktemp -d):/run systemd-app

Note: Most of this material, including the Dockerfile itself, appear to be taken from this blog post by Daniel Walsh: Running systemd within a Docker Container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.