We also used a fixed ip address in our containers, but we used a different container with nginx to do the reverse proxy. The idea is that on our Container host (Windows Server 2016) we install only Docker and nothing more. All configuration is done in containers. Thus, we can easily switch to another host.
This is a Docker file for nginx proxy
FROM microsoft/windowsservercore SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] ARG NgInxVersion="1.13.5" ENV NgInxZipUrl="http://nginx.org/download/nginx-${NgInxVersion}.zip" RUN Invoke-WebRequest -Uri $env:NgInxZipUrl -UseBasicParsing -Outfile c:\\nginx.zip RUN Expand-Archive -Path c:\\nginx.zip -DestinationPath c:\\nginx WORKDIR "c:\\nginx\\nginx-${NgInxVersion}" COPY ./nginx.conf conf\\nginx.conf ENTRYPOINT powershell .\\nginx.exe
Note that nginx.conf copied to the nginx configuration folder. It contains reverse proxy settings. Excerpt from http node for one of our sites:
server { listen 80; server_name somesite.mydomain.com; location / { proxy_pass http://172.22.108.6/; } }
The nginx container should start with -p 80:80
When we add new containers, we run a powershell script that updates nginx.conf and reloads nginx. (it will be rare)
Example:
- User is browsing http://somesite.mydomain.com
- Our DNS redirects somesite.mydomain.com to the ip of our host container
- Since port
80 open for the nginx container, the request goes there - nginx will proxy request
172.22.108.6 - The user sees a web page running on the container with ip
172.22.108.6
source share