我正在准备通过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 defaultCOMMAND
using the DockerfileCMD
instruction.
As the operator (the person running a container from the image), you can override thatCMD
instruction just by specifying a newCOMMAND
.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/