2017年6月19日 星期一

[ 常見問題 ] systemctl - Failed to get D-Bus connection: Operation not permitted

Source From Here
Question
I'm trying to list services on my CentOS image running in Docker using
# systemctl list-units

but I get this error message:
Failed to get D-Bus connection: Operation not permitted

Any suggestions what the problem might be?

How-To
My guess is that you're running a non-privileged container. systemd requires CAP_SYS_ADMIN capability but Docker drops that capability in the non privileged containers, in order to add more security.

systemd also requires RO access to the cgroup file system within a container. You can add it with –v /sys/fs/cgroup:/sys/fs/cgroup:ro So, here a few steps on how to run CentOS with systemd inside a Docker container:
1. Pull centos image
2. Set up a docker file like the one below:
  1. FROM centos  
  2. MAINTAINER “Yourname" @address.com>  

  • ENV container docker  
  • RUN yum -y update; yum clean all  
  • RUN yum -y install systemd; yum clean all; \  
  • (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”]  

  • 3. Build it - docker build --rm -t centos7-systemd - < mydockerfile
    4. Run a container with docker run --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup centos7-systemd /usr/sbin/init
    5. You should have systemd in your container

    If you want an exist docker image to be capable of systemd, you can try "sethrosetter/centos7-systemd-sshd"

    沒有留言:

    張貼留言

    [Git 常見問題] error: The following untracked working tree files would be overwritten by merge

      Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...