首页 > 解决方案 > 带有 envsubt 的 Dockerfile

问题描述

FROM nginx:alpine
COPY /build /usr/share/nginx/html 
RUN rm /etc/nginx/conf.d/default.conf 
#COPY nginx/nginx.conf /etc/nginx/conf.d 
COPY nginx/nginx.template /etc/nginx/conf.d 
EXPOSE 80 
CMD envsubst < /etc/nginx/conf.d/nginx.template > /etc/nginx/conf.d/nginx.conf && exec nginx -g 'daemon off;'

我的 nginx.conf 文件。

server {

  listen 80;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;


  }
    error_page   500 502 503 504  /50x.html;

    location = /50x.html {
    root   /usr/share/nginx/html;

 }
}

我的模板文件

server {

  listen ${PORT};

  location / {
    root   /usr/share/nginx/html;

    index  index.html index.htm;

    try_files $uri $uri/ /index.html;

  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {

  root   /usr/share/nginx/html;

  }
}

以上是我的dockerfile。启动容器后,我检查了 config.d 文件夹,没有找到任何 nginx.conf 文件。似乎它没有使用 envsubt 生成任何文件。但后来我跳到交互模式并运行 envsubt 命令它确实生成了文件。我的情况似乎是什么问题?

标签: linuxdockernginx

解决方案


推荐阅读