Docker on Windows 2016 : A simple webserver

Posted by Brian Keyes

Jun 22, 2017 11:14:00 AM Docker, Docker Containers, Azure, windows containers

 In our example today we are going to discuss how to create a simple web server (IIS) and run it in a container . We will also inject some of our custom HTML for the example. The prerequisite for this lab would be to have a Windows 2016 server running Docker.If you haven't deployed a Windows 2016 server for Docker yet, check out this post to get started. 

Our simple webserver example will use a 2016 Server "with containers" and both the container and the host will expose port 80, as depicted in the image below..

port 80.jpgOnce we have our Windows 2016 server with Docker on it, we will RDP to our Windows host and run the command: 

docker run -d --name webserver1 -p 80:80 microsoft/iis

 

The "-d" is for detached more that will run this in the background .

 

cont name .jpg

The " --name " will give this container a proper name "webserver1" in this instance .

 

port 80-2.jpg

The-p is for "publish" we see 2 ports listed here. The first port in our example is for the HOST and the second is for the CONTAINER.The final part of the command is refers to the IMAGE that this CONTAINER will be built from. Docker checks locally for a CONTAINER matching this name locally first.

docker hub.jpg

If Docker cannot find the IMAGE locally Docker checks with Docker Hub to see if it can find an image matching the name . If it can Docker downloads this to the local instance. If you dont have the image locally it may take several minutes for the image to download from Docker Hub to your local Docker engine. 

 

 

After the command completes  you can see the running container with the "docker ps" command.  Lets look briefly at the information displayed here with "docker ps". What do we know about this container?

docker ps.jpg

From left to right , the CONTAINER ID is the Docker generated ID for the container , the IMAGE we recognize from the earlier command is the IMAGE upon which the CONTAINER is based. With the status and created we know that it is up and running. Finally we see the proper name "webserver1" that we supplied in the run command. At this point you should be able to map the commands used to run the container with the results of "docker ps".

 

Next lets connect to the container we just started with the command , but first let me explain the command we are going to use. 

docker exec -i webserver1 cmd 

The "exec" command tells docker to run a command in a running container . The "i" keeps STDIN ( standard in ) open and "webserver1' is how we reference our container and 'cmd' is to open a command prompt.  

 

Look carefully at the prompt and you will notice that you are on C:\ and  not in the admin directory any longer . You are INSIDE the container now. To show this, Run 'docker' here and see the result.  Since this is INSIDE the container and the command will not work.  compair-1.jpg

 

However, running the command  "hostname" will result in the container name, illustrating that we are indeed within a container and not on the Windows 2016 host.

run docke r.jpg

 

 For our simple example, we are now going to be replacing the default IIS landing page with some custom text by doing the following:  

del C:\inetpub\wwwroot\iisstart.htm

and then running: 

echo "this content hosted inside an IIS container!!!!" > C:\inetpub\wwwroot\index.html

 

Once we have this new IIS page create, we can access it by browsing to it from another machine by entering the IP of the Windows 2016 server into a web browser. 

this content .jpg

 

While this is a simple example, it shows that we can easily deploy IIS inside a Windows container and have it served up on a Windows 2016 server.  More complex examples can get into the use of Docker swarms, Docker volumes, and release pipelines, but this basic example is the foundation for getting up to speed quickly with IIS and Windows containers.  

Posted by Brian Keyes

Brian has over 20 years of experience as a Systems Engineer with a strong background in VMware, storage, networking and security. Brian has worked for variety of US Govt. entities over the years;DOD,NGA,NNSA and others. Currently focused on Docker technologies

Find me on:

    
Request a Complimentary Docker Consultation

An Open View

Vizuri Blog

Subscribing to our blog is a great way to stay up to date with the latest information from Vizuri, as well as our strategic partners. We focus on providing a range of content that is practically useful and relevant from both a technical and business perspective.

We promise to respect your privacy.

×