How to detect reverse proxy in docker windows container

I am launching a container for a docker window in a 10-year Windows release window and want to configure IIS as a reverse proxy for the container. Per https://blogs.technet.microsoft.com/virtualization/2016/05/25/windows-nat-winnat-capabilities-and-limitations/ it seems that this is impossible, since it is impossible to bind the internal NAT range using the local host . This leaves a dynamically assigned IP address that can only be detected by running the docker validation command after the image is launched. I hope there is a more efficient way that I skip.

+5
source share
2 answers

We solved this problem by assigning an IP address in the default subnet for each Windows container and exporting port 80 from the container. This gave us a stable address to introduce into the ARR Reverse proxy rule. For example, the following creates a container at 172.20.118.129, and then checks that the container is running at the requested address.

PS C:\WINDOWS\system32> docker run -d --name myservice --ip=172.20.118.129 microsoft/iis:nanoserver 7d20d8a131805727868ddf85f7c1f455fa2489bb2607b250e694a9e530a61302 PS C:\WINDOWS\system32> docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myservice 172.20.118.129 
+2
source

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
+1
source

Source: https://habr.com/ru/post/1265518/


All Articles