docker - 如何在 Docker 的 sh 环境中设置好 apache2ctl 的 PATH
问题描述
这是我的 Dockerfile :
FROM debian
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/web/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get -y -q upgrade && apt-get -y -q install apache2
RUN apt-get update && apt-get -y -q upgrade && apt-get -y -q install apache2
EXPOSE 80 443
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND","&"]
当我启动容器时,系统正在调用 apache2 代替 apache2ctl 并且我收到以下错误消息:
:~/strech_apache$ docker container run -ti -p 80:80 system/strech_apache
Usage: /usr/sbin/apache2 [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-k start|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
-D name : define a name for use in <IfDefine name> directives
.../...
Action '-D FOREGROUND &' failed.
The Apache error log may have more information.
当我在交互模式下运行我的 Dockerfile 作为容器时CMD
,我能够启动apache2ctl -D FOREGROUND &
并且我已经让默认的 apache 页面正常工作。
更新
当我使用CMD
以下行完成我的 Dockefile 时:
CMD ["apache2ctl","-D","FOREGROUND"]
我的错误信息变成了这样:
system@vmdebian:~/strech_apache$ docker container run -ti -p 80:80 system/strech_apache:strech
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
system@vmdebian:~/strech_apache$
如果我这样写我的 CMD 也是一样的:
CMD ["service","apache2","restart"]
我收到了这条消息
system@vmdebian:~/strech_apache$ docker container run -ti -p 80:80 system/strech_apache:strech
[....] Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
. ok
看起来像apache打开/关闭,容器随着apache2的停止而停止
如何让 apache2 仍在运行?
解决方案
从"&"
您的CMD
.
这里有两个潜在的问题,并且&
都删除了修复:
使用CMD ["command", "arg", "..."]
表单时,Docker 根本不运行 shell;它只是直接运行命令并传入它给出的参数。您使用三个参数CMD
运行,、 和。 使用它给出的参数启动,但它不理解为参数,这是你得到的错误。apache2ctl
-D
FOREGROUND
&
apache2ctl
apache2
&
此外,您的CMD
(或ENTRYPOINT
)必须将其进程作为前台进程运行。如果您在 shell 中键入命令并立即返回 shell 提示符,如果您尝试将该命令作为容器中的主命令,则容器将在您启动时立即退出。你不想要这里通常的shell“在后台运行”的含义&
;您希望 Apache 作为前台进程运行,并且只要 Apache 正在运行,容器就可以运行。
推荐阅读
- python-3.x - 用python从互联网下载文件?
- python - 如何做相当于在numpy中设置一个带有序列的数组元素?
- c# - 无法在 DNN 9.9 中加载 MVC 模块
- gemfire - 更改区域添加加载到该区域的缓存时无法实例化类
- html - 填充html中剩余的行空间
- java - JIT 编译器是否会优化局部变量
- azure - 如何从命令行将 webapp 部署到 Azure
- asp.net - ASP.NET C# 图像文件未进入文件夹
- javascript - 在输入字段中选择单个、多个文件
- javascript - npm install 不工作,从 git 克隆我的项目后无法安装任何节点模块