CentOS / sig-cloud-instance-images

CentOS cloud images
780 stars 563 forks source link

centos7.4 systemctl Failed to get D-Bus connection: Operation not permitted #104

Open kuncao opened 6 years ago

kuncao commented 6 years ago

hello experts according to https://github.com/docker-library/docs/tree/master/centos#systemd-integration docker build --rm -t local/c7-systemd . [root@szvphicpra31005 systemddockerfile]# docker build --rm -t local/c7-systemd . Sending build context to Docker daemon 2.56 kB Step 1/5 : FROM centos:7 ---> 2d194b392dd1 Step 2/5 : ENV container docker ---> Running in a3f2620de0fe ---> 389ecdd1fbe8 Removing intermediate container a3f2620de0fe Step 3/5 : 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/*; ---> Running in 0bd9b2653955 ---> a26fdc1712dd Removing intermediate container 0bd9b2653955 Step 4/5 : VOLUME /sys/fs/cgroup ---> Running in 6159dd8f4ca1 ---> 1433aca36e39 Removing intermediate container 6159dd8f4ca1 Step 5/5 : CMD /usr/sbin/init ---> Running in 791a6376b0fd ---> 4922bc8d4b2a Removing intermediate container 791a6376b0fd Successfully built 4922bc8d4b2a [root@szvphicpra31005 systemddockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE local/c7-systemd latest 4922bc8d4b2a 6 minutes ago 195 MB

business Dockerfile :do not confused with the attached systemd base image ########################## build secomanager dockerfile ########################### FROM local/c7-systemd MAINTAINER caokun caokun.nj@huawei.com ENV container docker ENV TZ Asia/Shanghai ENV http_proxy YourOwnAccountInHuaweiSuchasc00286473:YourOwnPassword@proxyus3.huawei.com:8080/ ENV https_proxy YourOwnAccountInHuaweiSuchasc00286473:YourOwnPassword@proxyus3.huawei.com:8080/ ENV all_proxy YourOwnAccountInHuaweiSuchasc00286473:YourOwnPassword@proxyus3.huawei.com:8080/ ENV no_proxy=127.0.0.1,.huawei.com,localhost,local,.local,10.120.165.217,*.huawei.com RUN yum install -y openssh-server vim telnet sudo wget unzip tar gcc openssl lsof service compat-libstdc++-33 systemctl RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN useradd guest RUN echo "guest:guest!@#" | chpasswd RUN echo "guest ALL=(ALL) ALL" >> /etc/sudoers RUN echo "root:Mylinux1" | chpasswd RUN sed -i '1s/^/set encoding=utf-8\n/' /etc/vimrc && echo "set hls" >> /etc/vimrc && echo "set expandtab" >> /etc/vimrc && echo "set sw=4" >> /etc/vimrc && echo "set tabstop=4" >> /etc/vimrc RUN sudo mkdir /root/packagessm ADD files/PreInstall_CentOS7.1.zip /root/packagessm/ ADD files/SecoManager_5.1.0.B010_ALL_install_config.zip /root/packagessm/ WORKDIR /root/packagessm

WORKDIR /root

RUN sudo mkdir /var/run/sshd EXPOSE 22 ENTRYPOINT /usr/sbin/sshd -D CMD ["/usr/sbin/init"] then build the business docker such as docker build --rm -t secom:v1 .

run business image as following commad docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 18002:18002 -p 1127:1127 -p 2222:22 --ip 172.20.0.3 --net smbridge -h SmServer --shm-size=36G --name secom secom:v1

enter docker docker exec -it secom /bin/bash [root@SmServer packagessm]# systemctl Failed to get D-Bus connection: Operation not permitted ----can not resolve the problem [root@SmServer packagessm]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)

please help what's wrong? thanks a lot

kuncao commented 6 years ago

solution:with -rm optiion such as docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro --privileged -d -p 18002:18002 -p 1127:1127 -p 2222:22 --rm --ip 172.20.0.3 --net smbridge -h SmServer --shm-size=36G --name secom secom:v1 [root@SmServer packagessm]# pwd /root/packagessm [root@SmServer packagessm]# ls PreInstall_CentOS7.1.zip SecoManager_5.1.0.B010_ALL_install_config.zip [root@SmServer packagessm]# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION dev-xvda1.device loaded activating tentative /dev/xvda1 -.mount loaded active mounted / dev-mqueue.mount loaded active mounted POSIX Message Queue File System etc-hostname.mount loaded active mounted /etc/hostname etc-hosts.mount loaded active mounted /etc/hosts etc-resolv.conf.mount loaded active mounted /etc/resolv.conf sshd-keygen.service loaded active exited OpenSSH Server Key Generation sshd.service loaded active running OpenSSH server daemon systemd-journald.service loaded active running Journal Service systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories -.slice loaded active active Root Slice system.slice loaded active active System Slice dbus.socket loaded active listening D-Bus System Message Bus Socket systemd-journald.socket loaded active running Journal Socket systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket basic.target loaded active active Basic System local-fs.target loaded active active Local File Systems multi-user.target loaded active active Multi-User System paths.target loaded active active Paths slices.target loaded active active Slices sockets.target loaded active active Sockets swap.target loaded active active Swap sysinit.target loaded active active System Initialization timers.target loaded active active Timers systemd-tmpfiles-clean.timer loaded active waiting Daily Cleanup of Temporary Directories LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 25 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. -------------other information---------------- --------------base image dockerfile---------- 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" ] #######added 20180322 ADD cmd.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/cmd.sh CMD ["/usr/local/bin/cmd.sh"] #######added 20180322 #######changed 20180322

CMD ["/usr/sbin/init"]

#######changed 20180322

cmd.sh file when compile base image

!/bin/bash

exec /usr/sbin/init # To correctly start D-Bus thanks to https://forums.docker.com/t/any-simple-and-safe-way-to-start-services-on-centos7-systemd/5695/8

-----------------------business dockerfile------------------------------------------ ########################## build secomanager dockerfile ########################### FROM local/c7-systemd MAINTAINER caokun caokun.nj@huawei.com ENV container docker ENV TZ Asia/Shanghai ENV http_proxy c00286473:password@proxyus3.huawei.com:8080/ ENV https_proxy c00286473:password@proxyus3.huawei.com:8080/ ENV all_proxy c00286473:password@proxyus3.huawei.com:8080/ ENV no_proxy=127.0.0.1,.huawei.com,localhost,local,.local,10.120.165.217,*.huawei.com RUN yum install -y openssh-server vim telnet sudo wget unzip tar gcc openssl lsof service compat-libstdc++-33 systemctl strace RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN useradd guest RUN echo "guest:guest!@#" | chpasswd RUN echo "guest ALL=(ALL) ALL" >> /etc/sudoers RUN echo "root:Mylinux1" | chpasswd RUN sed -i '1s/^/set encoding=utf-8\n/' /etc/vimrc \ && echo "set hls" >> /etc/vimrc \ && echo "set expandtab" >> /etc/vimrc \ && echo "set sw=4" >> /etc/vimrc \ && echo "set tabstop=4" >> /etc/vimrc RUN sudo mkdir /root/packagessm ADD files/PreInstall_CentOS7.1.zip /root/packagessm/ ADD files/SecoManager_5.1.0.B010_ALL_install_config.zip /root/packagessm/ WORKDIR /root/packagessm

WORKDIR /root

RUN sudo mkdir /var/run/sshd #############for ssh

EXPOSE 22

ENTRYPOINT /usr/sbin/sshd -D

#############for ssh CMD ["/usr/sbin/init"]

command to build base image docker build --rm -t local/c7-systemd . command bo build business image docker build --rm -t secom:v1 .

other information [root@szvphicpra31005 Sm_Docker]# docker --version Docker version 17.03.0-ce, build 3a232c8 docker 内的os [root@SmServer packagessm]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)

antoinetran commented 6 years ago

Your issue is unreadeable! Add some code tag like test for more people to help you.

ilanmimoun commented 6 years ago

Up please

Hugo1380 commented 6 years ago

Same issue here, except I obtain the error during the Build Time :

Step 5/7 : RUN systemctl enable syslog-ng && systemctl start syslog-ng
 ---> Running in 9b275df09cee
Failed to get D-Bus connection: Operation not permitted
The command '/bin/sh -c systemctl enable syslog-ng && systemctl start syslog-ng' returned a non-zero code: 1

My Dockerfile :

FROM centos_systemctl:latest 

RUN yum -y update
RUN yum -y install epel-release && \
    yum -y install vim && \
    yum -y install wget && \
    yum -y install rsync && \
    yum -y groupinstall "Development tools"
# Install syslog-ng 3.14
RUN cd /etc/yum.repos.d/ && \
    wget https://copr.fedorainfracloud.org/coprs/czanik/syslog-ng314/repo/epel-7/czanik-syslog-ng314-epel-7.repo && \
    yum -y install syslog-ng
RUN systemctl enable syslog-ng && systemctl start syslog-ng
RUN yum -y remove rsyslog
# COPY config syslog-ng
CMD ["/usr/sbin/init"]

centos_systemctl:latest from https://github.com/docker-library/docs/tree/master/centos#systemd-integration

Thanks,