apache - 准备Docker容器以通过Shell或exec进行最坏情况的救援

标签 apache docker

我正在准备通过Dockerfile在前台运行apache的docker容器:

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

我构建它,运行它,当我启动它时,我将apache放在前台,并且可以通过它来控制它
docker exec mycontainer dosomething

但是,如果我以某种方式弄乱了它,例如通过放置损坏的apache配置或ssl证书,而apache由于错误而不再启动。这意味着整个容器将不再启动,并且我无法使用docker exec对其进行修复。

所以我正在寻找的是一种让apache在前台运行的方法,只要一切正常,就使用docker exec,但是如果apache遇到启动问题,我想将容器启动到bin / bash而不是apache前台模式。

有没有办法做到这一点?如何确保我不会因为apache启动问题而被锁定在容器之外?谢谢!

最佳答案

but if apache has startup problems i want to start up the container into bin/bash instead of apache foreground mode



是的,any parameter passed to docker run would override the CMD ones:
docker run -it <yourApacheImage> bash

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

This command is optional because the person who created the IMAGE may have already provided a default COMMAND using the Dockerfile CMD instruction.
As the operator (the person running a container from the image), you can override that CMD instruction just by specifying a new COMMAND.

How can i ensure that I do not get locked out of the container because of Apache startup problem?



您完全可以:它启动失败,它将处于“退出”模式,因此您必须删除该容器。
然后,通过bash session 开始一个新的 session ,然后在该bash中尝试重新启动Apache:当Apache再次失败时,您位于容器中并可以查看日志。

关于apache - 准备Docker容器以通过Shell或exec进行最坏情况的救援,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33718579/

相关文章:

apache - 网络套接字不起作用

authentication - 使用 docker 设置 redis

Docker Buildx 无法从本地拉取继承的镜像

php - 使用官方 php docker 镜像并在启动时运行 memcached

docker - 为什么 docker 容器总是被杀死

apache - httpd 服务器未启动:(13) 权限被拒绝:make_sock:无法绑定(bind)到地址 [::]:88

php - 为 Ubuntu 14.04 安装和配置 xampp

apache + redmine 403 - 权限良好

php - htaccess 仅在未提供参数的情况下将一个域重定向到另一个域?

docker - 无法看到rstudio服务器日志文件