>  Q&A  >  본문

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일 전1127

모든 응답(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;'" 정답 위층
    명령: 컨테이너가 실행된 후 실행될 명령은 docker run 문의 명령으로 재정의될 수 있습니다.

    회신하다
    0
  • 취소회신하다