如何在不停止的情况下在 Docker 容器中运行 Nginx? [英] How to run Nginx within a Docker container without halting?
问题描述
我在 Docker 容器上安装了 Nginx,并尝试像这样运行它:
I have Nginx installed on a Docker container, and am trying to run it like this:
docker run -i -t -p 80:80 mydockerimage /usr/sbin/nginx
问题在于 Nginx 的工作方式是,初始进程立即生成一个主 Nginx 进程和一些工作进程,然后退出.由于 Docker 只观察原始命令的 PID,因此容器会停止.
The problem is that the way Nginx works, is that the initial process immediately spawns a master Nginx process and some workers, and then quits. Since Docker is only watching the PID of the original command, the container then halts.
如何防止容器停止?我需要能够告诉它绑定到第一个子进程,或者阻止 Nginx 的初始进程退出.
How do I prevent the container from halting? I need to be able to tell it to bind to the first child process, or stop Nginx's initial process from exiting.
推荐答案
nginx
和所有表现良好的程序一样,可以配置为不自我守护.
nginx
, like all well-behaved programs, can be configured not to self-daemonize.
使用 http://wiki.nginx.org 中描述的 daemon off
配置指令/CoreModule.
Use the daemon off
configuration directive described in http://wiki.nginx.org/CoreModule.
这篇关于如何在不停止的情况下在 Docker 容器中运行 Nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!