docker运行nginx为什么要使用 daemon off
再返回Nginx的docker仓库仔细查看说明,其实是有说明的 /捂脸~
就是在CMD后面加上exec nginx -g 'daemon off;'
,如下:
- command: /bin/bash -c "echo 'hello' && exec nginx -g 'daemon off;'"
Nginx的docker仓库原文说明如下:
- If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
- Running nginx in debug mode
- Images since version 1.9.8 come with nginx-debug binary that produces verbose output when using higher log levels. It can be used with simple CMD substitution:
- $ docker run --name my-nginx -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx nginx-debug -g 'daemon off;'
- Similar configuration in docker-compose.yml may look like this:
- web:
- image: nginx
- volumes:
- - ./nginx.conf:/etc/nginx/nginx.conf:ro
- command: [nginx-debug, '-g', 'daemon off;']
If you add a custom CMD in the Dockerfile, be sure to include -g daemon off;
in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
-- 这里的CMD
适用 docker-compose.yml 中的entrypoint
和command
,以及 Dockerfile 中的ENTRYPOINT
和CMD
。
也就是说:
Docker 容器启动时,默认会把容器内部第一个进程,也就是
pid=1
的程序,作为docker容器是否正在运行的依据,如果 docker 容器pid=1的进程挂了,那么docker容器便会直接退出。Docker未执行自定义的CMD之前,nginx的pid是1,执行到CMD之后,nginx就在后台运行,bash或sh脚本的pid变成了1。
所以一旦执行完自定义CMD,nginx容器也就退出了。
https://hub.docker.com/_/nginx/
docker运行nginx为什么要使用 daemon off的更多相关文章
- docker 运行jenkins及vue项目与springboot项目(四.docker运行nginx)
docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...
- docker 运行nginx并进入容器内部、端口映射
一.docker运行容器 1.从网易蜂巢镜像仓库下载nginx镜像 : 2.拉取镜像到本地,并查看本地的镜像: $ docker pull hub.c..com/library/node:latest ...
- Docker容器里的进程为什么要前台运行?相同的问题:docker运行apache为什么带FOREGROUND参数?docker运行nginx为什么带`daemon off`参数?
<第一本Docker书>里面,讲到Docker容器启动web服务时,都指定了前台运行的参数. 例如apache: ENTRYPOINT [ "/usr/sbin/apache2& ...
- Docker运行Nginx服务器
一.获取Docker容器的Nginx镜像 二.创建Docker容器宿主机挂载目录 # 创建挂载目录,-v 显示创建的目录名 [root@idclooknet ~]# mkdir -vp /opt/do ...
- docker运行nginx
docker run --name nginx(容器名) -p 80:80 -v 项目文件路径:/usr/share/nginx/html -v 配置文件路径:/etc/nginx/nginx.con ...
- docker部署nginx
1. 下载nginx [root@localhost my.Shells]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ ...
- docker使用nginx反向代理springboot
docker运行nginx容器 快速安装运行 docker-hub文档 https://hub.docker.com/_/nginx 拉取nginx1.6.0 docker pull nginx:1. ...
- docker 运行jenkins及vue项目与springboot项目(二.docker运行jenkins为自动打包运行做准备)
docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...
- 如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目
如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目 #1:前提准备 1.1 首先请确认你的电脑是windows10专业版或企业版,只有这 ...
随机推荐
- 用 Vue 改造 Bootstrap,渐进提升项目框架[转]
GitChat 作者:Meathill 原文:用 Vue 改造 Bootstrap,渐进提升项目框架 关注微信公众号:「GitChat 技术杂谈」 一本正经的讲技术 [不要错过文末彩蛋] 前言 Vue ...
- mongodb 按配置文件mongodb.conf启动
命令如下 mongod --config /etc/mongodb.conf
- JAVA-SpringMVC基于注解模式第一个应用
项目文件结构 1. web.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <web-app x ...
- z-index的堆叠规则
原文: https://www.cnblogs.com/starof/p/4424926.html 对于所有定位,最后都不免遇到两个元素试图放在同一位置上的情况.显然,其中一个必须盖住另一个.但,如何 ...
- (转)【风宇冲】Unity3D教程宝典之AssetBundles:第一讲
自:http://blog.sina.com.cn/s/blog_471132920101gz8z.html 原创文章如需转载请注明:转载自风宇冲Unity3D教程学院 ...
- Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10
Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10 Updated by JR on Mar ...
- C#.NET常见问题(FAQ)-override覆盖和virtual虚类如何理解
父类使用virtual关键字,可以让子类的实例完全代替基类的类成员.(前面父类virtual后面子类override),比如下面我定义一个Employee的员工的基类,给这个基类定义了Start_Wo ...
- Discuz常见小问题-如何批量加精,置顶帖子
批量选中帖子,然后置顶和精华都可以勾选 完成之后的效果
- Swift语言精要 - Dictionary(字典)
字典以键值对的形式存储数据. 键不能重复,但是值可以重复. 基本语法用例: var states : Dictionary<String, String> = ["CA" ...
- PHP Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
$html = file_get_contents("http://www.somesite.com/"); $dom = new DOMDocument(); $dom-> ...