如何在Docker容器中运行Nginx而不停止? [英] How to run Nginx within a Docker container without halting?

查看:1294
本文介绍了如何在Docker容器中运行Nginx而不停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

推荐答案

code> nginx ,像所有表现良好的程序一样,可以配置为不进行自我后台管理。

nginx, like all well-behaved programs, can be configured not to self-daemonize.

使用守护程序关闭 http://wiki.nginx.org/CoreModule中描述的配置指令

这篇关于如何在Docker容器中运行Nginx而不停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆