banjocode How To Install Docker On WSL

How To Install Docker On WSL

This is the quickest way to install Docker on WSL and sync it with your Docker containers.

3 min read

Configure Docker for Windows

First, we need to expose a port in Docker for Windows for it to work in WSL.

docker for windows

Install Docker

This is how you install Docker in your WSL environment - it is taken from Docker’s installation docs. Just copy and paste basically. This is for Ubuntu 18.04.

# Update the apt package list.
sudo apt-get update -y

# Install Docker's package dependencies.
sudo apt-get install -y 

# Download and add Docker's official public PGP key.
curl -fsSL | sudo apt-key add -

# Verify the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.
# If you want to live on the edge, you can change "stable" below to "test" or
# "nightly". I highly recommend sticking with stable!
sudo add-apt-repository 
   "deb [arch=amd64]    $(lsb_release -cs)    stable"

# Update the apt package list (for the new apt repo).
sudo apt-get update -y

# Install the latest version of Docker CE.
sudo apt-get install -y docker-ce

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $USER

After this, close and open a new terminal, so you can run Docker without sudo.

Install Docker Compose

Installing Docker Compose can be done via PIP or the normal apt-get way.

# Install Python 3 and PIP.
sudo apt-get install -y python3 python3-pip
pip3 install --user docker-compose

# Or install only Docker Compose
sudo apt-get install docker-compose

Add bin to your PATH

You need to add /home/<username>/.local/bin to your PATH.

Edit your ~/.profile file with nano ~/.profile and add a new line anywhere in the file. Add the text export PATH="$PATH:$HOME/.local/bin"

Run source ~/.profile to activate your new path.

Confirm that it works by running echo $PATH.


You might need to export the following variable to make it work. You can write it either in ~/.zshrc or in ~/.bashrc.


Modify WSL configurations

If you are running Windows 10 18.03+ or newer, it might be good to make some changes. sudo nano /etc/wsl.conf to edit your configurations file.

root = /
options = "metadata"

This will allow you to work from /c instead of /mnt/c, and also fixes some of your permissions. You need to sign out of Windows to make this work.