我是docker新手。在我们的docker环境中已经安装并运行了Apache。
现在我需要进入容器,修改httpd.conf
文件,保存后需要重启Apache。
请问,我该怎么做? 我对“exec”和“attach”命令感到非常困惑。
我是docker新手。在我们的docker环境中已经安装并运行了Apache。
现在我需要进入容器,修改httpd.conf
文件,保存后需要重启Apache。
请问,我该怎么做? 我对“exec”和“attach”命令感到非常困惑。
无需附加或执行(实际上这本来就是一项调试功能)
您可以使用docker cp
将本地版本的 httpd.conf
复制到容器中。(这样,您可以在本地环境舒适地修改文件)
docker cp httpd.conf <yourcontainer_name>:/path/to/httpd.conf
完成后,您可以发送USR1信号请求优雅重启(请参见docker kill
语法):
docker kill --signal="USR1" <yourcontainer_name>
请将 <yourcontainer_name>
替换为正在运行 Apache 的容器 ID 或名称。
仅当容器启动的主进程是
CMD ["apachectl", "-DFOREGROUND"]
点击访问 "Docker: How to restart a service running in Docker Container" 了解更多。
更新Apache配置需要执行以下步骤:
Replace Apache configs.
If you have config folder mapped from outside of container you should update configs outside of container.
If your apache configs are stored inside of container, you will need to run something like this:
docker cp httpd.conf YOUR_CONTAINER_NAME:/path/to/httpd.conf
Do Graceful Apache restart:
sudo docker exec -it YOUR_CONTAINER_NAME apachectl graceful
通过打开bash shell进入容器:
docker exec -it containerName bash