Skip to content
vanpeerdevelopment edited this page Jan 14, 2016 · 2 revisions
# Dockerfile
FROM nginx:1.9.9

ENV dws_api_proxy dws_back-end_1:8080

RUN rm /etc/nginx/conf.d/default.conf
COPY dws-dist/ /data/dws/
COPY dws.conf /etc/nginx/conf.d/

COPY start.sh /usr/bin/start.sh
CMD ["/bin/bash", "/usr/bin/start.sh"]
# dws.conf
server {

    server_name     localhost;
    listen          80;
    root            /data/dws;
    
    location / {        
        index  index.html;
    }

    location /api {
        proxy_pass http://dws-back-end;
    }
}
# start.sh
(echo "upstream dws-back-end { server $dws_api_proxy; } " 
        && cat /etc/nginx/conf.d/dws.conf) > /tmp/dws.conf
mv /tmp/dws.conf /etc/nginx/conf.d/dws.conf
nginx -g "daemon off;"

The DWS frontend exists of a set of html, js and css files which are the end result of the gulp build. These files are hosted on nginx. All requests from the browser are sent to the nginx server. The server will then decide whether it can serve the data itself or proxy to request to the backend.

The DWS frontend image is based on the standard nginx 1.9.9 image. The dws_api_proxy environment variable will be used as a location to proxy all API calls received on nginx. All API calls will be proxied to the backend container.

The nginx base image will load all configuration files in /etc/nginx/conf.d/ on startup. The files will be included in the main configuration file in an http block. The default configuration is removed and a DWS specific configuration is added. DWS will listen to port 80 on localhost and serve all data in the /data/dws/ folder. Request for /api will be proxied to http://dws-backend which is defined in start.sh.

The start script will be executed when the docker container is started. In the startup script the dws_api_proxy environment variable is read and added to the start of the /etc/nginx/conf.d/dws.conf file as upstream server. It would also be possible to use the environment variable in the nginx configuration file using lua or perl modules. But those modules aren't available by default.

Clone this wiki locally