This article is based on a personal experience.
Being a newbie to the docker, I might be wrong on some stuffs!
Please feel free to correct me through the comment!
For personal, education, non-commercial or small business(fewer than 250 employess and less than $10 million in annual revenue) use, Docker Desktop is free in Windows.
So you don't have to read this article and just go download Docker Desktop.
For those who are not belong to above groups, you have to pay to use Docker Dekstop.
But what if you don't want to pay and use Docker in Windows?
You can do this by installing Docker Engine. But there is requirements to do before starting.
Set Up WSL(Windows Subsystem for Linux)
Enable Allowing WSL in your Computer
Control Panel > Programs > Programs and Features > Turn Windows features on or off
Click box on Windows Subsystem for Linux
Or run below command on Cmd or Powershell that is running as administrator
$ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Install Windows Terminal (Optional) and Linux System (Essential) from Microsoft Store
After Completing Step 1 and 2, you can finally use wsl in your computer.
Installing Docker Engine is pretty simple.
You just have to go to below link and follow the guideline that the docker is providing.
Since it can be confusing, I will write down How I installed a docker engine in my computer, but it will be very similar to what is written in above documentation
aptpackage index, and it is recommended to use this command once a week in a linux if you want to update your linux packages to latest version since linux does not automatically update its package like Windows
$ sudo apt-get update
aptto use a repository over HTTPS
$ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
testor both repository, just add each or both word after
stablein above command.
stable: latest releases for general availability
nightly: latest builds of work in progress for the next major release
test: pre-releases that are ready for testing before general availability (GA)
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
$ apt-cache madison docker-ce
Following above instructions, you are done with installing docker engine in your WSL.
It is time to test if docker engine works correctly by running hellow-world cotainer!
However, there is one more thing to discuss. Docker Daemon!
Docker daemon is a persistent background process that manages the containers on a single host, which means that docker daemon needs to be run before running any container.
Below command will run docker daemon, and you must keep running it to use any container.
$ sudo dockerd &
& makes command run in background in linux
With running docker daemon in a background, run below code which will run hello-world container.
sudo docker run hello-world
If the result is same as above picture, then you successully run hello-world with docker!
If you get below error, when you try to start a docker daemon,
$ failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
run below code and rerun docker daemon
$ sudo killall -9 dockerd
Above error occurs, because you are trying to run docker daemon when docker daemon is already running.
-9 stands for
sigkill and the solving command will kill all signal related to docker daemon.