Skip to content

Setting up Docker

Ryan Godwin edited this page May 2, 2024 · 5 revisions

The template requires docker.

Because some projects need the CUDA toolkit, we have to use docker-ce inside of WSL rather than Docker Desktop with a WSL backend. (At least as of May 2022). If you don't plan to use a GPU, you can use standard Docker installation protocols.

Ensures no older packages are installed

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

Ensure pre-requisites are installed

 sudo apt-get update
 sudo apt-get install ca-certificates curl gnupg

Adds docker apt key

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Adds docker apt repository

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

Refreshes apt repos

sudo apt-get update

Installs Docker CE

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

Ensures docker group exists

sudo groupadd docker

Ensures you are part of it

sudo usermod -aG docker $USER

Now, close your shell and open another for taking the group changes into account

Systemd

Make sure your /etc/wsl.conf in Ubuntu contains

[boot]
systemd=true

Then, restart WSL by opening powershell and running wsl --shutdown, waiting 8 seconds, then opening another Ubuntu shell.

Confirm Installation

First, run

docker version

You should get no permissions errors if things went well. If you do get permission errors, try again running as root (e.g., sudo docker version)

You can then try

docker run hello-world

References and more information:

https://docs.docker.com/engine/install/ubuntu/ (seems to be updated)

https://dev.to/felipecrs/simply-run-docker-on-wsl2-3o8 (not being updated, but original way we setup docker-cd in Ubuntu)