Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在docker构建期间运行systemctl enable xxx?_Docker_Dockerfile_Containers - Fatal编程技术网

如何在docker构建期间运行systemctl enable xxx?

如何在docker构建期间运行systemctl enable xxx?,docker,dockerfile,containers,Docker,Dockerfile,Containers,我希望这个问题能让你们都好起来 我目前正在尝试创建一个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/syste

我希望这个问题能让你们都好起来

我目前正在尝试创建一个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

有什么想法吗?

您的构建正在尝试执行特权操作。问题是,
--privileged
标志在生成时不可用。这是一个有趣的问题:

TL;docker博士似乎有两种可能性

  • 启用实验模式,然后运行--security=unsecure./xxx.RUN,如下所述
  • 安装buildx cli插件,然后安装docker buildx build--allow security.unsecurity,如下所述

docker之外的另一个解决方案是使用
buildah
,但这是一个较长的解决方案。但是一个有趣的例子,特别是如果你在RedHat生态系统中工作,因为他们想要摆脱Docker而支持Buildah/Podman。这是我的建议。虽然我不清楚它是如何解决您的问题的,但它被强调能够处理此类问题。

您的构建正在尝试执行特权操作。问题是,
--privileged
标志在生成时不可用。这是一个有趣的问题:

TL;docker博士似乎有两种可能性

  • 启用实验模式,然后运行--security=unsecure./xxx.RUN,如下所述
  • 安装buildx cli插件,然后安装docker buildx build--allow security.unsecurity,如下所述

docker之外的另一个解决方案是使用
buildah
,但这是一个较长的解决方案。但是一个有趣的例子,特别是如果你在RedHat生态系统中工作,因为他们想要摆脱Docker而支持Buildah/Podman。这是我的建议。虽然我不清楚它是如何解决您的问题的,但它被强调能够处理此类问题。

在docker容器中为非docker应用程序使用安装程序的情况。。。这是一项与客户合作的成果

在docker容器中为未停靠的应用程序使用安装程序的情况。。。这是一项与客户合作的成果

您可以改为在虚拟机中运行此应用程序吗?Systemd非常不适合在Docker中运行,如果安装程序希望
systemctl启动
一些东西,那么在Systemd运行时实现这一点将非常困难。您可以在虚拟机中运行此应用程序吗?Systemd非常不适合在Docker中运行,如果安装程序希望
systemctl启动
一些东西,那么在Systemd运行时实现这一点将非常困难。