ホームページ  >  に質問  >  本文

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

PHPzPHPz2707日前1130

全員に返信(2)返信します

  • 高洛峰

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

    envsubst はおそらく環境変数を操作するものだと思います。詳しくはコマンドの説明を参照してください

    daemon off: これは nginx のパラメーターであり、
    command は docker run nginx /bin/sh のイメージ名 nginx の後の /bin/sh の部分です。任意のコマンドを実行できます
    1 つの投稿でそれを言わないでください

    返事
    0
  • PHPz

    PHPz2017-04-24 09:16:02

    /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf
    設定ファイルを置き換えます
    nginx -g 'daemon off; ' "正解は二階
    コマンド: コンテナーの実行後に実行されるコマンドは、docker run ステートメント内のコマンドによってオーバーライドできます。

    返事
    0
  • キャンセル返事