Run Docker on Windows¶
It is my first blog write in English.
If there's anything wrong please inform me...
Preview¶
If you are using Linux or MacOS in your computer, there are certain circumstances that you need Windows to run some applications or for development use.
And to run windows in other systems there are often three ways:
- Install Windows and get dual system
- Run Windows with VMs(Virtual Machine)
- Run Windows in Docker
- Run Windows App Via Wine
Note
We are mainly dealing with docker in this tutorial.But I'd like to show you the advantages and disadvantages of each method before we start so that you can make a better choice.
If you knows what you are doing, just skip to the next part.
Install Windows and get dual system
The only but fatal disadvantage of this method is that usually , you have to restart your computer to exit the current system and get into windows.The advantage is obvious since you are running a real windows physically, you got all your hardwares working for a better performance.
Run Windows with VMs
This is more convinient than restart your computer. A Virtual Machine monitors the hardware, so that you're running your windows quite seperately.The disadvantage is that you waste your RAM and CPUs for running the VMs, so that it can slow down both inside and outside the VMs. And the installing process can be quite complex.
Run Windows in Docker
This aproach is what we concentrate on today.Using Docker, your get a rather seperated environment to run programs smoothly. Docker is like a container that provide just the amount of dependencies that you need. It's the best choice if you don't have a wonderful computer.
Run Windows App Via Wine
Wine is tailored for running some small Windows App. If you're running a small project or a .exe
file, wine will be enough. But it can not run a big project or a big app.
Quick choose
If you don't mind restart everytime you want to use Windows, choose "Install Windows and get dual system"
If you have a good computer and a good tutorial, choose VMs
If you just want to run some windows applications, try docker.
If you just want to run a .exe
file, try wine.
Qick Start¶
Tip
Two ingredients are all we need: Docker Engine and a RDP server.
Docker Engine¶
What is Docker Engine:
Docker Engine is an open source containerization technology for building and containerizing your applications.
It is highly recommended to install docker engine from the official webite, where you can learn more.
To learn more about docker, see this article ---> What is Docker.
-
Follow the steps from the official website and install docker.
-
To check if you have installed docker, try this:
- To check if everything is working perfectly, try this:
Hello from Docker!
This message shows that your installation appears to be working correctly.
Tip
If you successfully installed docker( have the version information ) but failed to run hello-world due to some internet issues:
Try sudo
first !
Only when you have your docker engine installed and working, follow the next steps.
Windows in Docker¶
Reference Tutorial: docker-windows
I will introduce two ways to install Windows in docker, choose the one fits your need.
Via Docker CLI¶
CLI stands for command-line interface. It is the easiest way to have windows run in your docker, just copy the following command into your terminal:
docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --device=/dev/net/tun --cap-add NET_ADMIN -v ${PWD:-.}/windows:/storage --stop-timeout 120 dockurr/windows
But before you run it let me explain the command
This command starts a Docker container to run Windows VM using KVM/QEMU virtualization. It enables hardware acceleration, network bridging, and persistent storage.
Key Parameters
-it
: Runs the container in interactive mode.
--rm
: Automatically removes the container when it exits (avoids leftover containers).
--name windows
: Assigns the name windows to the container.
-p 8006:8006
: Set port so that you can access the container at port 8006 (don't change it)
--device=/dev/kvm
: Use KVM (Kernel-based Virtual Machine) for hardware-accelerated virtualization.
--device=/dev/net/tun
: Use TUN/TAP, enabling bridged or NAT networking for the VM.
--cap-add NET_ADMIN
: Gives the container network administration privileges.
-v ${PWD:-.}/windows:/storage
: Use ./windows to store the VM (you can change the directory).
--stop-timeout 120
: Allows 120s for the VM to shut down safely.
dockurr/windows
: The Docker image designed for running Windows VMs.
Basically you can just copy the command.
How to use
When you run the command, docker first download an image of windows. And after pulling the image, it will start the service.Then, move to your browsers and go to http://[your_localhost]:8006
. You will see the process of installing windows and so on.
Just wait a few minutes till the process automatically finish. Then you got windows in your browser.
Via Docker Compose¶
To personalize your Windows VM, it is more recommanded to use docker compose
than the previous command. Follow the steps:
- Create a folder for your Windows storage, in my case it's
./windows
. - Enter the folder and build a
compose.yaml
file in it. - Create two more folders:
data
andshare
.
- Paste these into the compose file:
services:
windows:
image: dockurr/windows
container_name: windows
environment:
VERSION: "11" # your windows version
RAM_SIZE: "3G" # the RAM size for your windows
CPU_CORES: "4" # the number of CPU cores for your windows
DISK_SIZE: "125G" # the disk size for your windows
devices:
- /dev/kvm
- /dev/net/tun
cap_add:
- NET_ADMIN
ports:
- 8006:8006
- 3389:3389/tcp
- 3389:3389/udp
volumes:
- ./share:/data # mount the share folder
- ./data:/storage # mount the storage folder
restart: always
stop_grace_period: 2m
Info
Feel free to customize the options with my comments. Unless you know what you're doing, paste the others.
./share:/data
means you mount ./share
in your current folder to /data
in the Windows VM so that you can exchange files between the two systems through this folder.
./data:/storage
means you use ./data
in your current folder to store your Windows.
- Save the compose file and run:
Again you can check the progress through your browser at
http://[your_localhost]:8006
. And you can start using it when it finishes initializing.
Tip
Using Windows in your browser maybe quite slow and you don't have audio and paste.
We're using RDP to solve that problem .
Using RDP¶
Now you already have Windows running and ready at port 8006. We're using the RDP server to make you more convinient to use.
Introducing RDP ( see wikipedia )
Remote Desktop Protocol (RDP) is a proprietary protocol developed by Microsoft Corporation which provides a user with a graphical interface to connect to another computer over a network connection.
In a word, RDP is good.
Install RDP
There're lots of RDP client you can use. If you're using Linux, I recommand Remmina. If you're using MacOS, Windows APP Mobile will be good.
Access Your Windows
I use Remmina as an example.
- Open Remmina and create a new connection ( the bottom at upper-left coerner )
The server name should be
[your_localhost]:3389
The Window's default user is docker
, the pssword be admin
- Save the setting and launch to connect.
Where to find the share folder
Your will find it at network -> host.lan -> Data
in Windows
Now you can enjoy your Windows