I am facing this error with this Dockerfile:

FROM centos:latest

ENV container docker
MAINTAINER The CentOS Project <[email protected]>

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 rpm -U https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
RUN yum -y install zabbix-agent
RUN yum clean all

COPY ./zbx-speedtest.sh /etc/zabbix/bin/zbx-speedtest.sh
RUN chmod +x /etc/zabbix/bin/zbx-speedtest.sh
COPY ./speedtest.conf /etc/zabbix/zabbix_agentd.d/speedtest.conf

COPY ./zabbix-speedtest.service /etc/systemd/system/zabbix-speedtest.service
COPY ./zabbix-speedtest.timer /etc/systemd/system/zabbix-speedtest.timer

RUN systemctl enable zabbix-speedtest.timer
RUN systemctl enable zabbix-agent.service
RUN systemctl start zabbix-agent.service
RUN systemctl start zabbix-speedtest.timer

CMD ["/usr/sbin/init"]

When trying to use either docker-compose or docker build I receive this error:

Failed to get D-Bus connection: Operation not permitted
ERROR: Service 'zbx' failed to build: The command '/bin/sh -c systemctl start zabbix-agent.service' returned a non-zero code: 1

I looked everywhere, nothing is up for a solution. If it is impossible to do that with docker, please tell me which container to learn that can do that?


Description=Run a speedtest every 5 minutes

# RandomizedDelaySec=30



Description=Run a speedtest

ExecStart=/etc/zabbix/bin/zbx-speedtest.sh --run

  • 2
    Generally docker containers don't have systemd running within them. Maybe try hub.docker.com/r/centos/systemd Jul 2, 2020 at 16:26
  • 1
    Putting an init system inside of a docker container is an anti-pattern.
    – jordanm
    Jul 2, 2020 at 17:44
  • what does this mean?
    – elekgeek
    Jul 2, 2020 at 19:44
  • 1
    @elekgeek See here. basically, something that you shouldn't do, and if you feel compelled to do it, there is something wrong in your design. In this case, you can run some of your system daemons as containers instead of plain processes (pattern) but running daemons inside your containers is an anti-pattern.
    – xenoid
    Jul 2, 2020 at 22:14
  • I don't understand why the courses I came across while trying to learn docker never mentioned this :) You know, I have to try things myself to learn, and ask the experts here who will write some lines that equal 20 hours of training, really.. Thank you guys!
    – elekgeek
    Jul 7, 2020 at 21:05

1 Answer 1


When I download and run centos:latest, it gives me a CentOS 8 Docker container that does not run systemd. You would need to do more to get systemd working, but you really should not need an init system since Docker is designed to run a single process inside its containers.

Looking at the Zabbix Agent Dockerfile produced by Zabbix, it does not try to use systemd.

Have you tried to use zabbix/zabbix-agent:centos-5.0-latest and see if that works any better?

Update after comments:

This is what your Dockerfile would possibly look like after using these recommendations:

FROM zabbix/zabbix-agent:centos-5.0-latest
ENV container docker

COPY ./zbx-speedtest.sh /etc/zabbix/bin/zbx-speedtest.sh
RUN chmod +x /etc/zabbix/bin/zbx-speedtest.sh
COPY ./speedtest.conf /etc/zabbix/zabbix_agentd.d/speedtest.conf

You would then need to adjust zabbix-speedtest.service and zabbix-speedtest.timer to run from the context of the host you will be deploying the Docker container on.

  • I used this container,but I need to run a script using either systemd timer or cron, any idea how I can use cron in zabbix container? Help appreciated, really.. if you look at the Dockerfile i posted in the question, you will see I am trying to run a script, thanks
    – elekgeek
    Jul 2, 2020 at 21:17
  • Instead of FROM centos:latest use FROM zabbix/zabbix-agent:centos-5.0-latest and add your script to the container image. Since cron is also another process that is likely not running in your container, it may be best to use cron or the systemd timer from the host to time your periodic runs. Maybe you can adapt your zabbix-speedtest.timer to run on the host using docker exec. Jul 2, 2020 at 21:49
  • I am really confused, seems I am thinking the old baremetal way, please guide me with more details how such Dockerfile should be done.
    – elekgeek
    Jul 3, 2020 at 12:27
  • I updated the answer to add a sample Dockerfile for your use case. You have not shared the contents of zabbix-speedtest.service and zabbix-speedtest.timer so I am unable to comment on how you might fix those. Jul 3, 2020 at 19:09
  • I added the content for zabbix-speedtest.timer and zabbix-speedtest.service
    – elekgeek
    Jul 4, 2020 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .