首頁  >  問答  >  主體

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 geneyour may be used as a workaround if you need

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 天前1132

全部回覆(2)我來回復

  • 高洛峰

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

    envsubst 大概是操作環境變數的東西,詳情看指令說明

    daemon off : 是nginx的參數, 表示不用後台啟動的方式
    command 是docker run nginx /bin/sh 中鏡像名nginx 後面那段/bin/sh, 可以執行任何命令
    好像在你別一個帖子說了

    回覆
    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;'" 樓上正解
    command: 容器執行後要執行的指令,可以被docker run語句中的指令覆寫。

    回覆
    0
  • 取消回覆