Install docker on WSL 2

1 – Make sure your WSL is enabled and running

On PowerShell:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

On PowerShell, WT, CMD or GitBash:
wsl --set-version <Distro> 2
wsl --set-default-version 2
wsl --list --verbose or wsl -l -v

If after that, it still doen’t work, execute this command as Admin on CMD and reboot Windows:
bcdedit /set hypervisorlaunchtype auto start

2 – Install on WSL

Start WSL on PowerShell, WT, CMD or GitBash:
wsl

Remove old packages:
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update

Install dependency packages:
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

(Optional) – Verify key fingerprint:
sudo apt-key fingerprint 0EBFCD88

Set up the stable repository for x86_64/amd64 archtecture:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ce

Install latest version of docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io

3 – (Optional) – Enable Docker usage to non-root user:

Add your username to the docker group:
sudo usermod -aG docker ${USER}

Apply the new group membership:
su - ${USER}

Confirm that your user is now added to the docker group:
id -nG

4 – Test instalation:

(sudo) docker run hello-world

5 – Install docker-compose

Download current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose

Test the installation:
docker-compose --version

Attention!

If after a reboot docker won’t start, up the service manually:
sudo service docker start

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.