Docker Containers: Windows & Linux Side by Side

Let’s setup a simple example. We’ll have an nginx (Linux) container that acts as a reverse proxy to an IIS (Windows) container.

First, lets switch to windows containers. Right click the Docker icon in your system tray, and choose “Switch to Windows containers…”. If you don’t see this option, you’re probably already there.

Next, let’s get the 2 web servers up and tested individually.

For the Linux machine, we know we’re going to need a little image customization to enable the proxy, so lets go ahead and start by creating the image. I the file C:\dockertest\ReverseProxy\Dockerfile with the contents below.

FROM nginx

Now that we have our dockerfile, lets build the image. We’re going to tag this image as “reverseproxy.”

docker build -t reverseproxy .
docker run -d --rm -p "8080:80" --name myproxy reverseproxy
docker run -d --rm -p "8081:80" --name myiis microsoft/iis
docker ps

Now, let’s test out our webservers. We can open a browser on the local machine and navigate to them via the ports we exposed in the command lines: http://localhost:8080 and http://localhost:8081

Great, both web servers are up and running. Now lets kill them and restart them using nginx to proxy to IIS. We’ll need to configure nginx to proxy the requests. We do this by creating a config file in /etc/nginx/conf.d. The last line of /etc/nginx/nginx.conf tells us that it imports everything from that folder. The key part of this file is line #8, note that the host name it is passing to is the same name we gave the IIS container.

If you’re using the same directory structure as me, this

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name _;

  location / {
    proxy_pass http://myiis;
    proxy_buffering on;
    proxy_buffers 12 12k;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
  }
}

Now, lets modify the Dockerfile to put this configuration file on our image.

FROM nginx

COPY ./default.conf /etc/nginx/conf.d/default.conf

Lets kill the running containers, rebuild the nginx image and restart the containers, this time, only exposing the nginx port.

docker kill myiis
docker kill myproxy
docker build -t reverseproxy .
docker run -d --rm -p "8080:80" --name myproxy reverseproxy
docker run -d --rm --name myiis microsoft/iis
docker ps

And now, the moment of truth.

There we go. Linux and Windows containers up and running side by side. Truth be told, I had some issues when I originally started to do this and started this blog to address how I overcame them. However, I didn’t run into them this time, so I guess I need to chalk it up to trying to do it at 4am the night I started playing with docker :).

Leave a Reply

Your email address will not be published. Required fields are marked *