Docker Community Forums

Share and learn in the Docker community.

CentOS 7 systemd

build
docker

(Andrewm659) #1

I am trying to build my first docker container to do smokeping or cacti.
For some reason i’m getting an error on DBus when building the container.

My OS version is CentOS 7 latest.
I’m using CentOS 7 for the container build.

rpm -qa|grep -i docker
docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
docker-devel-1.3.2-4.el7.centos.x86_64
docker-latest-v1.10-migrator-1.13.1-58.git87f2fab.el7.centos.x86_64
docker-novolume-plugin-1.13.1-68.gitdded712.el7.centos.x86_64
docker-latest-1.13.1-58.git87f2fab.el7.centos.x86_64
docker-lvm-plugin-1.13.1-68.gitdded712.el7.centos.x86_64
docker-v1.10-migrator-1.13.1-68.gitdded712.el7.centos.x86_64
python2-dockerpty-0.4.1-9.el7.noarch
docker-distribution-2.6.2-2.git48294d9.el7.x86_64
docker-client-1.13.1-68.gitdded712.el7.centos.x86_64
docker-unit-test-1.13.1-68.gitdded712.el7.centos.x86_64
docker-1.13.1-68.gitdded712.el7.centos.x86_64
docker-latest-logrotate-1.13.1-58.git87f2fab.el7.centos.x86_64
docker-forward-journald-1.10.3-44.el7.centos.x86_64
python-docker-pycreds-1.10.6-4.el7.noarch
python-docker-py-1.10.6-4.el7.noarch
docker-client-latest-1.13.1-58.git87f2fab.el7.centos.x86_64
docker-logrotate-1.13.1-68.gitdded712.el7.centos.x86_64
docker-compose-1.9.0-5.el7.noarch

Here is the command I use to run the build

sudo docker build . --rm -t smokeping:1.1

Here is my Dockerfile

FROM centos:centos7
MAINTAINER me: version 1.0
ENV container docker
RUN yum update -y; yum clean all
#RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs dbus*
#RUN systemctl mask dev-mqueue.mount dev-hugepages.mount systemd-remount-fs.service sys-kernel-config.mount sys-kernel-debug.mount sys-fs-fuse-connections.mount
#RUN systemctl mask display-manager.service systemd-logind.service
#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" ]
#RUN systemctl disable graphical.target
#RUN systemctl enable multi-user.target
#VOLUME ["/run"]
#CMD ["/usr/lib/systemd/systemd"]
RUN yum install epel-release -y && yum install smokeping echoping fping.x86_64 httping dhcping hping3 ioping tcping httpd mod_ssl openssh-server passwd -y
EXPOSE 80
RUN systemctl enable httpd
RUN systemctl enable smokeping
#RUN systemctl enable dbus
#RUN systemctl start dbus
RUN systemctl start httpd
RUN systemctl start smokeping
CMD ["/usr/sbin/init"]

Here is the output at the end of the build

Failed to get D-Bus connection: Operation not permitted
The command '/bin/sh -c systemctl start httpd' returned a non-zero code: 1

What am I doing wrong?


(Bryce Ryan) #2

You may need to start your container with the --init flag. Have a look at this page for some guidance around running multiple services in a container: https://docs.docker.com/config/containers/multi-service_container/


(David Maze) #3

It’s probably easiest if you assume that commands like systemctl or service just don’t work in Docker, and come up with a different way to try to run your application. Usual practice is to not run an init system at all, and just run your service as a foreground process as the container’s default CMD.

(As two bonuses, it’d get rid of about 3/4 of your Dockerfile, and it wouldn’t require you to run your container as --privileged.)


(Andrewm659) #4

Ok so I took your advice and tried it this way

FROM centos:centos7
MAINTAINER “me"
ENV container docker
RUN yum update -y
RUN yum install epel-release -y && yum install smokeping echoping fping.x86_64 httping dhcping hping3 ioping tcping httpd mod_ssl -y
EXPOSE 80
RUN systemctl enable httpd smokeping
#RUN systemctl start httpd smokeping
CMD ["/usr/sbin/init"]
#CMD /usr/sbin/httpd

So I then tried to run it using the following command:

sudo docker run adc0d5822273 -it -p 80:80 /bin/bash

and got the following error:

 sudo docker run adc0d5822273 -it -p 80:80 /bin/bash
container_linux.go:247: starting container process caused "exec: \"-it\": executable file not found in $PATH"
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"-it\": executable file not found in $PATH".
ERRO[0000] error getting events from daemon: net/http: request canceled

Where did I go wrong?


Having trouble running Some /etc/init.d shell scripts
(Andrewm659) #5

Ok so I figured out my issue above. But if I enter the docker container and I want to check if httpd and smokeping are started I get the following:

[root@016a7fd3bac8 /]# systemctl status smokeping
Failed to get D-Bus connection: Operation not permitted
[root@016a7fd3bac8 /]#

(Martin Terp) #6

Hi

You are not going to get that to work in Docker.
What I use, in the rare cases i need multiple services running in same container, is supervisor.

quick example:

services.conf:

[program:sshd]
directory=/usr/local/
command=/usr/sbin/sshd -D
autostart=true
autorestart=true
redirect_stderr=true

[program:someOtherService]
directory=/usr/local/
command=/usr/sbin/Otherservice -D
autostart=true
autorestart=true
redirect_stderr=true

Dockerfile

RUN apt-get install -y supervisor
ADD sshd.conf /etc/supervisor/conf.d/services.conf
CMD /usr/bin/supervisord -n


Docker run issue
Multiple applications in a single container!