Installing Docker on WSL on a Data Science VM Windows 2022

I’ve made no secret that I really like the Data Science VM on the Azure Marketplace. Part of the reason being that it comes preconfigured with some many tools required for modern software and AI development. But there are gaps, and one of those gaps is that WSL is not installed, and so neither is Docker on WSL.

If you want to see my previous post, you can see the steps to get WSL configured on your machine.

Step 1 – Run the following commands, from a wsl terminal, to setup the components to install Docker:

```bash
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Run an apt-get update to pull the latest packages:
sudo apt-get update

```

Step 2 – Run the following commands to install docker:

```bash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

Step 3 – Verify successful install of Docker:

```bash
sudo systemctl status docker
```

You will see the following, and then can hit "Ctrl+C" to cancel out of the command:
![alt text](../images/docker-verify.png)

Step 4 – You can validate docker further by running the following commands:

```bash
sudo docker images
```

Step 5 – By default, docker requires “sudo” to run, this will need to be changed. You can update this by running the following commands:

```bash
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
```

Step 6 – Verify this worked by running the following commands:

```bash
docker images
docker pull hello-world
docker run hello-world
```

Leave a Reply

Your email address will not be published. Required fields are marked *