docker - solita/docker-systemd docker-compose
问题描述
我想在 docker-compose 中使用带有 systemctl 的图像,我在互联网上看到了这个图像https://github.com/solita/docker-systemd,它工作得很好,但是当我尝试将它与 docker- 一起使用时撰写它不工作(它工作但 systemctl 不工作,它给出此错误“系统尚未使用 systemd 作为初始化系统(PID 1)启动。无法运行。”)
test1:
container_name: 'test1'
build: './test'
volumes:
- /:/host
- /sys/fs/cgroup:/sys/fs/cgroup:ro
security_opt:
- "seccomp=unconfined"
tmpfs:
- /run
- /run/lock
privileged: true
构建文件是 test.sh
#!/bin/sh
set -eu
if nsenter --mount=/host/proc/1/ns/mnt -- mount | grep /sys/fs/cgroup/systemd >/dev/null 2>&1; then
echo "The systemd cgroup hierarchy is already mounted at /sys/fs/cgroup/systemd."
else
if [ -d /host/sys/fs/cgroup/systemd ]; then
echo "The mount point for the systemd cgroup hierarchy already exists at /sys/fs/cgroup/systemd."
else
echo "Creating the mount point for the systemd cgroup hierarchy at /sys/fs/cgroup/systemd."
mkdir -p /host/sys/fs/cgroup/systemd
fi
echo "Mounting the systemd cgroup hierarchy."
nsenter --mount=/host/proc/1/ns/mnt -- mount -t cgroup cgroup -o none,name=systemd /sys/fs/cgroup/systemd
fi
echo "Your Docker host is now configured for running systemd containers!"
解决方案
如果您想在 docker 中运行“systemctl”来启动/停止服务,那么您可以在没有 systemd 的情况下执行此操作。docker -systemctl-replacement就是为此而设计的。
推荐阅读
- java - 在运行时交换 Jackson 自定义序列化器/反序列化器
- javascript - 在 ThreeJs 中使用按钮的 3d 对象移动
- python-3.x - 在python中定义矩阵时放置常量
- xml - 如何以结构化的方式将表格结构转换为纯文本
- c++ - 使用 async cpp boost socket 时减少响应时间
- mongodb - 使用 MongoDb 聚合管道根据特定类型查询前 10 项
- python - 如何有效地读取非常大的 gzip 压缩日志文件的最后一行?
- sql - 在 T-SQL 中为表创建或更改
- sql - 如何在 Presto SQL 中应用 sum() 查询并面对函数 sum 的意外参数 (varchar)
- python - 查找列表中包含重复值的每个元素的索引