Skip to content

Instantly share code, notes, and snippets.

@Adhjie
Forked from dehsilvadeveloper/0_prerequisites.md
Created December 13, 2024 08:48
Show Gist options
  • Save Adhjie/8dcab8ef69a82e0b35d017725f20de19 to your computer and use it in GitHub Desktop.
Save Adhjie/8dcab8ef69a82e0b35d017725f20de19 to your computer and use it in GitHub Desktop.
Installing Docker on WSL 2 with Ubuntu 22.04

Prerequisites

Before start the installation process, make sure you meet the following prerequisites:

  • A Windows 10 operating system with WSL 2 support.
  • WSL 2 enabled.
  • Ubuntu 22.04 installed on WSL 2.

Step 1: Update the system

Before installing Docker, it is a good practice to ensure that all system packages are up to date. Open the Ubuntu terminal in WSL 2 and run the following command:

sudo apt update && sudo apt upgrade -y

Step 2: Install dependencies

Install the required dependencies for Docker:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Step 3: Add Docker GPG Key

Add the official Docker GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Add the Docker Repository

Add the Docker repository to the system:

echo "deb [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

Step 5: Install Docker Engine

Update repositories and install Docker Engine:

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 6: Add you user to Docker Group

Add your user to the Docker group to avoid the need to use sudo on every Docker command:

sudo usermod -aG docker $USER

Step 7: Check the installation

Close the open terminal on Ubuntu.

Restart WSL via the Windows command line (Powershell).

wsl --shutdown

Access Ubuntu again. Check if Docker was installed correctly on the Ubuntu terminal:

docker --version

You should get a response similar to this:

Docker version 26.1.4, build 5650f9b

Extra tips

Docker start up and shut down

To start the Docker service run the following on the Ubuntu terminal:

sudo service docker start

To stop the Docker service run the following on the Ubuntu terminal:

sudo service docker stop

Projects location

The performance of WSL 2 lies on running everything within Linux, so avoid running your projects with Docker from the /mnt/c path, as you will lose performance.

Opening folders via terminal

You can open a folder from Ubuntu with Windows Explorer by typing the command on your Ubuntu terminal:

explorer.exe .

The folder will be open using the Windows Explorer.

Remember to navigate to the desired folder on Ubuntu terminal beforehand.

Copy folder from Windows to Ubuntu

On the Ubuntu terminal confirm that you can access the mounted drive and all its directories using the command below.

sudo ls /mnt/*

You have to see the list of folders and files currently present on your Windows C:/ folder.

If you can see the items just fine, then navigate until the destination folder on the Ubuntu terminal and use the following command.

cp -r /mnt/c/my-folder .

Where "my-folder" is the name of the folder on Windows that you want to copy and "." indicates the destination. Since that we are already on the destination folder we can use just "." , but you can inform the desetination path too.

cp -r /mnt/c/my-folder /home/my-user/my-folder

Opening project on Visual Studio Code

You can open a project with the IDE Visual Studio Code by typing the command on your Ubuntu terminal:

code .

Remember to navigate to the desired folder on Ubuntu terminal beforehand.

Free cached memory on Ubuntu

To free cache memory on Linux Ubuntu running on WSL you can use the following command on the Ubuntu terminal:

echo 1 | sudo tee /proc/sys/vm/drop_caches

Windows Terminal

To access your environment through Windows, I recommend using the Windows Terminal by Microsoft, also available on the Windows Store. This tool includes CLI tabs, a high degree of customization, and even native WSL support to open Linux-based windows.

Want to learn more?

If you want to see the official documentation, visit https://docs.docker.com/desktop/wsl/

@airtonix
Copy link

airtonix commented Apr 2, 2025

I'd set your /etc/wsl.conf to

[automount]
enabled = false

[interop]
enabled = false
appendWindowsPath = false

[boot]
command = service docker start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment