【发布时间】:2020-04-08 02:54:22
【问题描述】:
我希望这个问题能让你一切都好。
我目前正在尝试创建 Docker 容器映像,但遇到了问题。 我最初对 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" ]
CMD ["/usr/sbin/init"]
并使用docker build -t baseimage . 将其保存为基本图像。到目前为止一切顺利。
应用程序的安装程序是一个 .run,其中执行类似 systemctl start xxx.service 之类的内容(我无法更改它,如果这部分失败,安装将失败)。
我已经为第二个Dockerfile尝试了一些东西,例如:
FROM baseimage
...
COPY xxx.run xxx.run
RUN ./xxx.run # This return an error like "Failed to get D-Bus connection: Operation not permitted"
...
并更改原始 CMD 以运行此脚本:
#! /bin/bash
/usr/sbin/init # With and without & after this one
./xxx.run
有什么想法吗?
【问题讨论】:
-
你可以在虚拟机中运行这个应用程序吗? Systemd 非常不适合在 Docker 中运行,如果安装程序期望
systemctl start某些东西,那么在 Systemd 运行时实现这一点将非常棘手。
标签: docker dockerfile containers