Skip to content

Instantly share code, notes, and snippets.

@gangadhars
Created January 8, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gangadhars/bf16b0a4f3c689a5f657363b4aae2e0f to your computer and use it in GitHub Desktop.
Save gangadhars/bf16b0a4f3c689a5f657363b4aae2e0f to your computer and use it in GitHub Desktop.
Run nginx container on custom port, using env variable "NGINX_PORT=<80>"
FROM nginx:latest
LABEL maintainer="Biarca"
COPY mysite.template /
CMD ["/bin/bash", "-c", "export NGINX_PORT=${NGINX_PORT:-80}; envsubst < /mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
server {
listen \${NGINX_PORT};
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
@tokiwinter
Copy link

Thanks for this - another great start for what I need. I'm planning on mirroring all the nginx images based on the seg3 value in this item in the lfccncf repository, using your trick with envsubst slightly abstracted via a script that will be the entrypoint.

As per https://hub.docker.com/_/nginx/ we can't just set NGINX_PORT as the author has noted in the README for this item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment