dockerはD-Bus接続を取得できません。操作は許可されていません。

dockerはD-Bus接続を取得できません。操作は許可されていません。

この 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"]

orを使用しようとすると、次のエラーがdocker-compose発生docker buildします。

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

周りを見回しましたが、解決策はありません。 Dockerを使用してこれが不可能な場合は、これを行うためにどのコンテナを学ぶ必要があるかを教えてください。

zabbix-speedtest.timer

[Unit]
Description=Run a speedtest every 5 minutes

[Timer]
OnCalendar=*:0/5
# RandomizedDelaySec=30

[Install]
WantedBy=timers.target

zabbix-speedtest.service

[Unit]
Description=Run a speedtest
After=network.target

[Service]
Type=simple
#User=zabbix-agent
#User=root
User=zabbix
ExecStart=/etc/zabbix/bin/zbx-speedtest.sh --run
CPUSchedulingPolicy=fifo
CPUSchedulingPriority=80

[Install]
WantedBy=multi-user.target

ベストアンサー1

ダウンロードして実行すると、centos:latest実行されていないCentOS 8 Dockerコンテナが提供されますsystemd。始めるにはもう少し作業が必要ですsystemdが、Dockerはコンテナ内で単一のプロセスを実行するように設計されているため、実際には初期化システムは必要ありません。

見ているZabbixによって作成されたZabbix Agent Dockerfile、使用しようとしませんsystemd

試してみて、zabbix/zabbix-agent:centos-5.0-latestよりうまく機能していることを確認してみましたか?

コメント後の更新:

これらの提案を使用した後、Dockerfileは次のようになります。

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

次に、Dockerコンテナをデプロイするホストのコンテキストで調整してzabbix-speedtest.service実行する必要があります。zabbix-speedtest.timer

おすすめ記事