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

标签 apache tomcat docker centos7

我创建了一个基于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/

相关文章:

mysql - 如何使用 Django/Apache/mod_wsgi/MySQL 在 EC2 上最大化性能?

c++ - 如何使用 Apache C 模块记录到文件

apache - 边缘NGram : Error instantiating class: 'org.apache.lucene.analysis.ngram.EdgeNGramFilterFactory'

unix - 使用非 root 用户 sudo-ing tomcat 启动与以 root 身份运行一样吗?

eclipse - 严重 : Servlet/JAXRS-HelloWorld threw load() exception java. lang.ClassNotFoundException : com. sun.jersey.spi.container.servlet.ServletContainer

java - Tomcat 7 中错误代码 500 的自定义错误页面

java - 为什么docker会报 "no such file or directory": unknown?

mongodb - Docker mongo image 始终将数据保存在/data/db 目录中

php - UTF-8贯穿始终

docker - 在 dockerfile 中运行 conda update 的问题