Tutorial: Docker Installation in WSL 2 of Windows

WSL, Ubuntu, Docker Installation, and Run a Docker

Sik-Ho Tsang
3 min readJun 27, 2022
Using Docker in WSL 2 (Image from Visual Studio Code)

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:
  1. First, WSL is installed first,
  2. By using WSL, we can install and run Linux OS such as Ubuntu.
  3. 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.)

Outline

  1. WSL and Ubuntu Installation
  2. Docker Installation and Run a Docker

1. WSL and Ubuntu Installation

wsl --list --online
List of Available Linux OS
  • 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
I forgot to capture the screen (this image is from iThome)
  • Ubuntu command window is popup, and UNIX username and password are requested.
Request for UNIX Username and password
  • 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

2.2. Install Docker

  • Click the setup file that just downloaded. The version is 4.9.1 for me.
Docker Installation

2.3. Activate WSL Integration in Docker

  • Start “Docker Desktop”. By clicking Settings > Resources > WSL Integration. Make sure WSL integration is activated:
Docker WSL Integration
  • (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
The getting-started docker
  • Then, in the browser, type:
http://localhost
http://localhost Saying Congratulations
  • We can see that the local host is just running, which means we just start a docker.

--

--

Sik-Ho Tsang
Sik-Ho Tsang

Written by Sik-Ho Tsang

PhD, Researcher. I share what I learn. :) Linktree: https://linktr.ee/shtsang for Twitter, LinkedIn, etc.

No responses yet