Skip to content

Instantly share code, notes, and snippets.

@nitinbhojwani
Created July 10, 2018 03:59
Show Gist options
  • Select an option

  • Save nitinbhojwani/136adf219ece9f44de46a5141a0422ad to your computer and use it in GitHub Desktop.

Select an option

Save nitinbhojwani/136adf219ece9f44de46a5141a0422ad to your computer and use it in GitHub Desktop.
Docker Image for UI application, to be served by Nginx server
FROM nginx:latest
# dist includes the built output - npm build
COPY dist /usr/share/nginx/html
# nginx*conf to copy all the nginx configuration files to image.
COPY nginx*conf /opt/app-name/
# copy app entrypoint shell script
COPY entrypoint.sh /opt/app-name/
# make entrypoint.sh executable
RUN ["chmod", "+x", "/opt/app-name/entrypoint.sh"]
# start the container with running the script
ENTRYPOINT ["/opt/sre-ui/entrypoint.sh"]
# expose a port from container where the nginx server is listening
EXPOSE 8080
#!/bin/bash
# read environment information from environment variable APP_ENV, defaults to 'local'
ENV="${APP_ENV:local}"
# copy the respective nginx configuration file, as per the environment
if [ "${ENV}" = "local" ] ; then cp /opt/app-name/nginx-local.conf /etc/nginx/conf.d/app-name.conf ; else cp /opt/app-name/nginx-prod.conf /etc/nginx/conf.d/app-name.conf ; fi
# run nginx in foreground, and not as daemon, because container watches initial process and is in running state
# based on only that process, so if nginx runs in foreground the process won't exit and hence container will keep running.
exec nginx -g "daemon off;"
# this includes the configuration, which is specific to the app
# overall nginx configuration like worker_processes, worker_connections etc is provided as default
# by nginx:latest docker image at /etc/nginx/nginx.conf
# override that as well, as per the need.
server {
listen 8080;
root /usr/share/nginx/html/;
index index.html;
# if app has base path then below location block is needed.
# for angular2 onwards, app hase base-href - https://angular.io/guide/router#base-href
location /base/path/for/app {
alias /usr/share/nginx/html/;
try_files $uri $uri/ /index.html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment