Home  >  Q&A  >  body text

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:命令本身表示什么意思?什么时候执行后面的命令?

PHPzPHPz2758 days ago1162

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-24 09:16:02

    envsubst is probably used to manipulate environment variables. Please see the command description for details

    daemon off: It is a parameter of nginx, which means that it does not start in the background.
    command is docker run nginx /bin/sh /bin/sh after the image name nginx, which can execute any command.
    It seems you said it in another post.

    reply
    0
  • PHPz

    PHPz2017-04-24 09:16:02

    /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf
    Replace the configuration file
    nginx -g 'daemon off;' "Correct answer upstairs
    command: The command to be executed after the container is running can be overridden by the command in the docker run statement.

    reply
    0
  • Cancelreply