Configure Windows Server for Docker Development
docker

Configure Windows Server for Docker Development

Configure a Windows Server for your Docker Development environment. Matching the Windows Host OS in Development is important for consistency across environments.

2019 has so far kicked off with a couple exciting Microsoft Docker projects. We are focusing on containerizing Microsoft applications running IIS, ASPNet, or other Windows workloads. One thing that became quickly apparent is the lack of information surrounding transforming native Microsoft applications to Docker.

This Windows series covers the build of the Windows Docker Server, build a Windows Stack of containers, and lastly transform native Windows applications to containers.When it comes to migrating an application from a native Windows installation to a Docker container, the information is a bit sparse. This guide aims to assist you with your transformation and avoid common pitfalls.

Now you may ask why we are using Windows Server instead of a Windows 10 VM. It is essential that we match the Operating System used in Development with the Production OS. The Microsoft Docker images are built and matched to the host Windows OS. If we were to run different OS's we could potentially pull completely different images from Docker. To avoid this pitfall run the same OS in Dev as what we run in Prod.

Prepare a Docker Windows Server Host

It is essential we prepare a Windows Server to host Docker for the task at hand. Docker Enterprise Edition is required when installing Docker on a Windows server. The Docker EE is slightly different installation compared to Docker for Windows as we install the Docker service which doesn't contain the Docker icon in the taskbar. Even though the version is named EE, it is still free for use in this configuration.

Install Docker on Windows Server

For this example, we use docker-compose to orchestrate multiple Docker containers. Using docker-compose makes the transition to Docker Swarm quite easy if you prefer to do so at a later stage.

Configure the Windows Server Development Environment

Run Microsoft Visual Studio Code (VS Code) directly on the Windows Server. Since we plan to experiment during the transformation, it is a quicker process to work directly on the server to fine tune all the Power Shell commands. VS Code has all the tools we need to run Docker commands as well as write code all from one screen. It reduces context switching between windows and in my opinion increases productivity.

Interacting with Docker using VS Code

Open a PowerShell terminal inside VS Code and interact with Docker. Next, write Dockerfiles and build them directly from VS Code. Finally, put everything together and Build, Ship, and Run your newly created containers all inside VS Code.

  • Inside VS Code navigate to View -> Terminal It opens a PowerShell terminal at the bottom of the VS Code application.
  • In the Powershell terminal: `docker run hello-world` This command will both pull and run the nano server hello-world Windows image and display the output.
    We are not able to interact with Docker and containers within VS Code. The next step is to write a Microsoft IIS Dockerfile, build, and run the newly created container.
  • Clone the example Docker Windows Server Repo: git clone https://github.com/56kcloud/docker-windows-server.git
  • In VS Code open the cloned Repo folder File -> Open -> docker-windows-server
  • Open a Terminal inside of VS Code Terminal -> New Terminal
  • Build the image: docker build -t docker4windows .
  • Run the container: docker run -d -p 8080:80 --name iis docker4windows
    The IIS container is now running on the Windows server. Windows has trouble to handle htttp://localhost correctly due to some NAT issues, so we have to grab the IP address directly from the IIS container.

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" my-running-site

The output is similar to this:

172.29.10.58

You can connect to the running container using the IP address from the inspect command and the configured port, http://172.29.10.58:8080.

Recap

We successfully set up a Windows Server and installed Docker EE for Docker development. Next, we installed Microsoft VS Code with the Docker plugin to interact with Docker. Finally, we built and ran the docker4windows image containing IIS and our sample website.The next article in the Windows series builds on this lesson to build a how a Windows stack. The stack contains multiple IIS containers connecting to a Microsoft SQL server.

0 Comments
Loading...