所以我想让 systemctl 在 docker 容器上工作以进行分配,所以我使用了命令:
docker run --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup s3696653/usap-a1 usr/sbin/init
一切运行良好,但我还没有完全阅读规范,我们不应该使用 systemctl。所以我停止了容器并尝试像平常一样运行容器:
docker run -i -t s3696653/usap-a1
但是它不再起作用了。 我收到错误:
Failed to mount tmpfs as /run: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.
我该怎么做才能使用正常的运行命令运行它? 提前致谢。
最佳答案
虽然建议不要在容器内使用 systemd 或使用特权模式,但建议并不是法令,如果不严格遵守,新泽西州警察会在晚上把你拖走并带走。如果您使用 --privilegedged 运行它,接下来尝试看看在没有它的情况下运行它需要什么,因为避免它会使您的设置更安全。
使用 -v (由 docker official documentation) 称为绑定(bind)挂载应该可以帮助您传递所需的卷,而不需要 --privileged 选项。事实上,这是来自旧 stackoverflow thread 的 systemd-in-docker 示例,询问类似的问题问题:
docker run -ti --tmpfs /tmp --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/centos7-systemd
关于Docker Centos7 : Failed to mount tmpfs as/run: Operation not permitted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63717749/