Tutorial: Docker Installation in WSL 2 of Windows
WSL, Ubuntu, Docker Installation, and Run a Docker
In this story, I record my steps by installing Docker in WSL of Windows. The full name of WSL is Windows Subsystem for Linux.
- While I can install docker in Windows directly, I want to use Linux commands such as curl. WSL is a good way to do it. Also, using WSL, I do not need Hyper-V or VM. Indeed, I just follow the procedures (link at the bottom) from Microsoft:
- First, WSL is installed first,
- By using WSL, we can install and run Linux OS such as Ubuntu.
- Finally, Docker is installed within Ubuntu.
Let’s get started !!! (Note: I made it on 26th June 2022. It may have some updates in the future which makes the procedures different, or it can have any other better ways for it.)
- WSL and Ubuntu Installation
- Docker Installation and Run a Docker
1. WSL and Ubuntu Installation
- Before installing WSL, first, we need to install Windows Terminal. If you got it, then it’s fine. We install it from: https://docs.microsoft.com/en-us/windows/terminal/install
- Open Windows Terminal using administrator, and run:
wsl --list --online
- There is a list of linux OS that we can have. But now, I got Ubuntu by running (There maybe needs for reboot to make WSL work.):
wsl --install -d Ubuntu
- Ubuntu command window is popup, and UNIX username and password are requested.
- After that, there should be saying that “Installation Successful!”.
- Next time if we want to use Ubuntu again, we can just find Ubuntu from the start menu.
2. Docker Installation and Run a Docker
2.1. Download Docker
- There is docker for Windows WSL in official docker website: https://docs.docker.com/desktop/windows/wsl/
- Click “Download Docker Desktop for Windows” to download.
2.2. Install Docker
- Click the setup file that just downloaded. The version is 4.9.1 for me.
2.3. Activate WSL Integration in Docker
- Start “Docker Desktop”. By clicking Settings > Resources > WSL Integration. Make sure WSL integration is activated:
- (For me, I need to enable Ubuntu integration and reboot my PC.)
2.4 Run a Docker in WSL Ubuntu
- In Ubuntu command prompt, run the getting-started docker:
docker run -dp 80:80 docker/getting-started
- Then, in the browser, type:
- We can see that the local host is just running, which means we just start a docker.
[Using Docker in WSL 2] https://code.visualstudio.com/blogs/2020/03/02/docker-in-wsl2
[Get started with Docker remote containers on WSL 2]
[Docker Desktop WSL 2 backend] https://docs.docker.com/desktop/windows/wsl/
[Getting Started Docker]
[Docker Installation] [Pulling Image] [Running Image] [Exporting/Saving Image] [Nvidia-Docker 2.0 Installation] [Docker Installation in WSL 2 of Windows]