Docker Hub官方Nginx镜像配置问题

Docker Hub官方Nginx镜像文档
https://hub.docker.com/_/nginx/
跟着文档说明进行配置,有些问题不知道什么意思,
原文引用:

using environment variables in nginx configuration

Out-of-the-box, Nginx doesn't support using environment variables inside most configuration blocks. But envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.

Here is an example using docker-compose.yml:

image: nginx
  volumes:
   - ./mysite.template:/etc/nginx/conf.d/mysite.template
  ports:
   - "8080:80"
  environment:
   - NGINX_HOST=foobar.com
   - NGINX_PORT=80
  command: 
        /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf    
        &&    
        nginx -g 'daemon off;'"

The mysite.template file may then contain variable references like this :

listen ${NGINX_PORT};

问题:
在代码部分最后一行,也就是command:那一行,
1、envsubst作用是什么?
2、daemon off;作用是什么?
3、command:命令本身表示什么意思?什么时候执行后面的命令?

阅读 6.3k
2 个回答

envsubst 大概是操作环境变量的东西,详情看命令说明

daemon off : 是nginx的参数, 表示不用后台启动的方式
command 是docker run nginx /bin/sh 中镜像名nginx 后面那段/bin/sh, 可以执行任何命令
好像在你别一个帖子说了

/bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf
替换配置文件
nginx -g 'daemon off;'" 楼上正解
command: 容器运行后要执行的命令,可以被docker run语句中的命令覆盖。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题