夏期劇*_*期劇場 9 mount systemd docker centos7 systemctl
(我是Docker初学者.然后我关注了CentOS-7的一些教程)
在我CentOS 7.2
,我尝试按照以下步骤学习Docker.
# 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
Run Code Online (Sandbox Code Playgroud)
所以到目前为止,一切(似乎)都可以.
现在我跑的时候问题出现了:
# 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.
Run Code Online (Sandbox Code Playgroud)
这甚至意味着什么,更重要的是,发生了什么,我该如何解决这个问题呢?
谢谢你们 :)
Tre*_*ams 26
在 Daniel Walsh 贡献了一系列补丁之后,更现代的方法是……
docker run -ti --tmpfs /tmp --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/centos7-systemd
Run Code Online (Sandbox Code Playgroud)
出于安全原因,本质上从特权容器开始是一个坏主意。由于 Daniel 贡献了补丁以使其变得不必要,因此我们可以在不升级权限的情况下开始。
虽然我们应该维护“每个容器单个服务/进程”的原则,但有些人希望运行 RedHat 支持的容器,这意味着使用 systemd。
有关更多信息,请参阅https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container/
为了演示一个精简的 systemd 容器,像这样的事情将运行 apache 和 tomcat;不是单一的服务/流程原则,而只是一个例子。你显然需要对这个图像做更多的事情,但这是基本的想法。我想我是从 Daniel 某处的一篇帖子中得到的,但我现在不记得了。
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/*;
RUN yum -y install httpd tomcat tomcat-javadoc.noarch \
tomcat-docs-webapp.noarch tomcat-admin-webapps.noarch ; \
yum clean all
RUN systemctl enable tomcat.service
RUN systemctl enable httpd.service
VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 80 8080
CMD ["/usr/sbin/init"]
docker build -t apache ./
docker run --tmpfs /tmp --tmpfs /run -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 8081:80 -p 8080:8080 --name apache apache
Run Code Online (Sandbox Code Playgroud)
arc*_*ess 18
尝试以特权模式运行容器:
docker run -ti --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/centos7-systemd
Run Code Online (Sandbox Code Playgroud)
这应该可以解决你的问题
归档时间: |
|
查看次数: |
13827 次 |
最近记录: |