Build and run Windows container

Running Windows container... wait what? Windows??? WTF?

Okay, take it easy genius! It gonna be alright! Microsoft has been working closely with Docker to add containerized applications for its OS platform. And, it's working nicely even though at first you will feel the pain in the ass.

There are a couple of things you need to take into account working with Windows container

  • First of all, you have to use a Windows machine to build and run Windows containers. Containers are using the underlying Operating System resources and drivers, so Windows containers can run on Windows only (Linux containers can run on Windows with WSL enabled).
  • If you're using Docker Desktop on Windows 10, you have to use it with Windows Container enabled.
  • There will be no GUI Windows environment (servercore or nanoserver) [1]. Of course, it's containers!
  • There will be no "latest" tag for your Windows base docker image.
  • Powershell is the King [2]. Just like any Linux container, you have to use a shell script (bash) to manipulate the OS your container is running in. In Windows, It's Powershell.
  • Chocolately package manager is the Queen [3]. Similar to apt (Debian, Ubuntu), or rpm (Redhat based OS)
Container tools on Windows architecture [6]

Let's run a sample Windows container and enjoy the greatness!
Prerequisite:
  • Docker Desktop using Windows Container mode
  • Windows 10
1. Compose a Dockerfile with the service you want to run in the Windows container (e.g. a Java application)

2. Open Powershell with Administrator privileges and run the following command to build the docker container

PS C:\Users\Trinh Nguyen\projects\mycontainer> docker build . -t yourimage_uri:yourtag

3. Run your containerized application from Powershell

PS C:\Users\Trinh Nguyen\projects\mycontainer> docker run -p 8080:8080 yourimage_uri:yourtag

That's it! You can read [4] and [5] for more references.

References

[1] https://searchwindowsserver.techtarget.com/tip/Clearing-up-the-Nano-Server-vs-Server-Core-confusion

[2] https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.1

[3] https://community.chocolatey.org/

[4] https://adamtheautomator.com/docker-windows-image/

[5] https://github.com/StefanScherer/dockerfiles-windows

[6] https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/containerd

Comments