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专业版或企业版,只有这 ...
随机推荐
- Android传感器应用——重力传感器实现滚动的弹球
一. 问题描述 Android中有多达11种传感器,不同的手机设备支持的传感器类型也不尽相同 1. 重力传感器 GV-sensor 2. 加速度传感器 G-sensor 3. 磁力传感器 M-se ...
- 关于android SDK安装Failed to fetch URL 一点思考
最近SDK出问题了,然后在google下载了一个android-sdk-windows.rar,然后点击SDK Manager,结果一直不能刷新API Level,然后就开始在网上找了好多资料,解决这 ...
- Android -- Camera.ShutterCallback
干货 相机拍照的回调 /** * Equivalent to takePicture(shutter, raw, null, jpeg). * * @see #takePicture(ShutterC ...
- 什么是哈希码(HashCode)
什么是哈希码(HashCode) 在Java中,哈希码代表对象的特征. 例如对象 String str1 = “aa”, str1.hashCode= 3104 String str2 = “bb”, ...
- 【Python】使用内置base64模块进行编解码
代码: import hashlib import base64 hash = hashlib.md5() hash.update('逆火Tu22m'.encode('utf-8')) print(h ...
- eclipse启动错误:java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer
转自:http://blog.csdn.net/niu_hao/article/details/9332521 eclipse启动时报错如下:java.lang.NoClassDefFoundErro ...
- 使用FractionSlider生成的视差幻灯效果原型
在线演示 本地下载 非常棒的jQuery插件,帮助你创建超酷的视差效果幻灯!
- Unity3d for beginners
tutorial addr: https://www.youtube.com/watch?v=QUCEcAp3h28 1.打开Unity3d File->newProject ->cre ...
- Android Studio 之 打包生成的 apk 安装包装到手机上闪退
今天,在 Android Studio 中的模拟器中测试 app 程序正常,然后打包 apk 安装包程序,发给领导后,领导反馈安装后打开闪退,抓紧安装到自己手机上,发现果然存在闪退.查阅资料后,解决方 ...
- PLT redirection through shared object injection into a running process
PLT redirection through shared object injection into a running process