Setup Docker on WSL with Ubuntu
Step by step guide to get Docker on WSL with Ubuntu distro.
Docker engine installation
Install Ubuntu, and execute:
sudo apt-get update
sudo apt-get upgrade
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2
Next two commands utilize ID
and VERSION_CODENAME
environmental variables. Check if they exist by using: echo -e "ID:$ID\nVERSION_CODENAME:$VERSION_CODENAME"
command to print them and check if any values are displayed. To get values that correspond to theses variables use: lsb_release -a | grep Codename
and lsb_release -a | grep ID
accordingly
curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo tee /etc/apt/trusted.gpg.d/docker.asc
echo "deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Almost rootless access
It's actually kind of workaround. Under the hood sudo
commands are executed withoud password needed.
sudo usermod -aG docker $USER
sudo visudo
sudoers file will be opened. Add:
%docker ALL=(ALL) NOPASSWD: /usr/bin/dockerd
%docker ALL=(ALL) NOPASSWD: /usr/bin/docker
Open or create .bash_alliases
file in Your home directory and add:
alias docker='sudo docker'
alias dockerd='sudo dockerd'