dockermountcentos7systemdsystemctl

Docker (CentOS 7 with SYSTEMCTL) : Failed to mount tmpfs & cgroup


(I'm a Docker beginner. Then I followed some tutorials for CentOS-7)

In my CentOS 7.2, I tried to learn Docker by following the steps below.

# docker version

Client:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 15:39:25 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 15:39:25 2016
 OS/Arch:      linux/amd64

# docker pull centos:latest
# docker images
centos     latest    778a53015523    12 days ago    196.7 MB

# mkdir ~/docker/centos7-systemd
# cd ~/docker/centos7-systemd
# vi Dockerfile
FROM centos
MAINTAINER "XXXX XXXX" <xxxx@xxxx.com>
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" ]
CMD ["/usr/sbin/init"]

# docker build --rm -t local/centos7-systemd .
..
Successfully built 1a9f1c4938b3

# docker images
centos                  latest    778a53015523    12 days ago    196.7 MB
local/centos7-systemd   latest    1a9f1c4938b3    8 seconds ago  196.7 MB

So up to this point, everything (seems) ok.
Now the problem comes when I run:

# docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/centos7-systemd
Failed to mount tmpfs at /run: Operation not permitted
Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.

What does this even mean, and more importantly, what is happening and how can I solve this, please?

Thank you all :)


Solution

  • try to run your container in privileged mode:

    docker run -ti --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/centos7-systemd
    

    this should solve your problem