gpt4 book ai didi

apache - Docker 在运行 Docker 启动命令时无法执行初始化脚本

转载 作者:行者123 更新时间:2023-11-28 22:28:56 25 4
gpt4 key购买 nike

我创建了一个基于CentOS 7的Docker镜像,希望Docker容器能够在我执行Docker run命令的同时自动启动Apache和Tomcat服务。

我的 docker 启动命令是:

sudo docker run --privileged -ti --name apache-tomcat-mobile --rm -v/software:/software -p 81:80 local/web-apache/app/scripts/start-web .sh

但是我总是报错:

exec format errorFATA[0000] Error response from daemon: Cannot start container 7332a91875c1aefb0d6c5160a69fe1c21058c06673b6e4058c81a8641af53baa: exec format error

我的start-web.sh只有两个task,一个是tomcat startup.sh,另一个是httpd -k start。

我已经为 start-web.sh 设置了足够的权限。

当我执行`sudo docker run --privileged -ti --name apache-tomcat-mobile --rm -v/software:/software -p 81:80 local/web-apache/bin/bash,没有错误发生。

The docker file I used based on CentOS7. The bas docker file is :
FROM centos:7
MAINTAINER "edao99" <jianghy_bj@hotmail.com>
ENV container docker
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
RUN yum -y update; yum clean all;\
(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"]

The actually docker filed used for apache and tomcat is inherited from the base docker. The apache docker file is:
FROM local/c7-systemd
RUN yum -y install gcc; yum clean all;
RUN yum -y install httpd; yum clean all;
RUN yum -y install apr-util-devel; yum clean all;
RUN yum -y install httpd-devel; yum clean all;
RUN yum -y install wget; yum clean all;
RUN yum -y install make; yum clean all;
RUN yum -y install tar; yum clean all;
RUN systemctl enable httpd.service
EXPOSE 80
CMD ["/usr/sbin/init"]

我在网上搜索了解决方案,没有发现类似的问题。谁能帮我解决这个问题?

谢谢。

最佳答案

您需要将运行的脚本复制到容器中,然后才能将其用作命令。您需要向 Dockerfile 添加一行,例如:

COPY start-web.sh /app/scripts/start-web.sh

确保将 start-web.sh 放在构建上下文中。

另外,如果你摆脱了 systemd 的东西,你的构建文件会简单得多。如果您必须拥有多个进程,请考虑使用一种更简单的进程管理工具,例如 Supervisor 或 Runit,或者编写您自己的 shell 脚本来启动服务。

关于apache - Docker 在运行 Docker 启动命令时无法执行初始化脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29865064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com