Docker Hub官方Nginx映像配置問題
PHPz
PHPz 2017-04-24 09:14:02
0
2
1128

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:指令本身表示什麼意思?什麼時候執行後面的指令?

PHPz
PHPz

学习是最好的投资!

全部回覆(2)
小葫芦

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

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

PHPzhong

/bin/bash -c "envsubst /etc/nginx/conf.d/default.conf
替換配置文件
nginx -g 'daemon off;'" 樓上正解
command: 容器執行後要執行的指令,可以被docker run語句中的指令覆寫。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!