Configure Windows Server for Docker Development

Learn how to configure Windows Server for Docker development. This guide covers installation, configuration, running Linux containers, and best practices for developing with Docker on Windows Server.

Configure Windows Server for Docker Development

2019 has so far kicked off with a couple of exciting Microsoft Docker projects. I started to focus on containerizing Microsoft applications running IIS, ASPNet, or other Windows workloads.

One thing that quickly became apparent was the lack of information surrounding transforming native Microsoft applications to Docker.

This Windows series covers building the Windows Docker Server, building a Windows Stack of containers, and transforming native Windows applications into containers. Information on migrating an application from a native Windows installation to a Docker container 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 that 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 installation is slightly different from 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 the Windows Server

For this example, we use docker-compose to orchestrate multiple Docker containers. If you prefer to transition to Docker Swarm at a later stage, using docker-compose makes it quite easy.

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 and 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, assemble everything and Build, Ship, and Run your newly created containers 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 and 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 following article in the Windows series builds on this lesson to build how a Windows stack. The stack contains multiple IIS containers connecting to a Microsoft SQL server.

FAQ Section: Configure Windows Server for Docker Development

Can you run Docker on Windows Server, and why would you want to?
Yes, you can run Docker on Windows Server, and it's especially useful for organizations that need to develop, test, and deploy Windows-based applications in a containerized environment. Running Docker on Windows Server allows you to leverage the benefits of containers, such as portability, resource efficiency, and consistent environments, while using familiar Windows tools and applications.

How do you install Docker on Windows Server?
To install Docker on Windows Server, first ensure that your server is running Windows Server 2016 or later, as Docker is natively supported on these versions. Then, use the following PowerShell commands to install Docker:

  1. Install the Docker provider: Install-Module -Name DockerMsftProvider -Repository PSGallery -Force.
  2. Install Docker: Install-Package -Name docker -ProviderName DockerMsftProvider.
  3. Start the Docker service: Start-Service Docker.
  4. Verify the installation by running docker --version.

After installation, Docker is ready to be used for container development on Windows Server.

What configurations are needed for Docker development on Windows Server?
For Docker development on Windows Server, configure the following:

  1. Networking: Ensure that the Windows Server network settings are properly configured to allow Docker containers to communicate with each other and external services.
  2. Storage: Set up Docker volumes to manage persistent storage for containers, ensuring data is retained between container restarts.
  3. Resource Limits: Adjust CPU, memory, and storage limits for Docker to optimize performance and prevent resource contention.
  4. Windows Containers: Choose between Windows Server Containers and Hyper-V isolation depending on your security and isolation needs.

These configurations help ensure that Docker runs efficiently and securely on Windows Server.

Can you run Linux containers on Windows Server?
Yes, you can run Linux containers on Windows Server by using the Windows Subsystem for Linux 2 (WSL 2) in conjunction with Docker Desktop. WSL 2 provides a lightweight Linux kernel that allows Docker to run Linux containers natively on Windows. This setup is ideal for developers who need to work with both Linux and Windows containers on the same machine.

What are some best practices for developing with Docker on Windows Server?
Best practices for developing with Docker on Windows Server include:

  1. Regular Updates: Keep Docker and Windows Server updated to the latest versions to ensure security and performance improvements.
  2. Container Security: Use Windows Defender or other security solutions to scan containers for vulnerabilities.
  3. Backup and Recovery: Implement backup strategies for Docker volumes and containers to prevent data loss.
  4. CI/CD Integration: Integrate Docker with continuous integration and deployment (CI/CD) pipelines to automate testing and deployment processes.

Following these best practices helps maintain a stable and secure Docker development environment on Windows Server.

Follow me

If you liked this article, Follow Me on Twitter to stay updated!