Skip to content

Installing Docker on Ubuntu WSL

paul-garster edited this page Oct 1, 2024 · 5 revisions

Installing and running applications within the Windows Windows Subsystem for Linux will greatly improve performance of file system operations.

  1. Open the Ubuntu terminal by searching for "Ubuntu" in the Start menu.

  2. Update the apt package list by running the following command:

    sudo apt-get update

  3. Install the necessary packages by running the following command:

    sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

  4. Add the Docker GPG key by running the following commands:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/docker.gpg

  5. Add the Docker repository to your apt sources list by running the following command:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  6. Update the apt package list again by running the following command:

    sudo apt-get update

  7. Install Docker by running the following command:

    sudo apt-get install docker-ce docker-ce-cli containerd.io

  8. Enable legacy iptables (docker won't work with iptables-nft).

    sudo update-alternatives --config iptables

    enter 1 to select iptables-legacy.

Verify that Docker is installed correctly.

  1. Start the Docker service by running the following commands:

    sudo service docker start

  2. Verify that Docker is running by running the following command:

    sudo docker run hello-world

This command should download and run a Docker container and output a "Hello from Docker!" message.

Post-installation steps. running as non-root user

To run docker without having to use sudo, you can create a docker group and add yourself to that group.

sudo groupadd docker

sudo usermod -aG docker $USER

Once you've this log out, and then connect to wsl again. Try running the hello-world example without using sudo.

docker run hello-world