User Tools

Site Tools


docker:install-docker-for-windows-wsl

This is an old revision of the document!


Install Docker in WSL and use it on Windows

First, install WSL for windows : search from start menu for “Turn Windows features on or off” and select “Windows Subsystem for linux

Next, install ubuntu:

wsl --set-default-version 2
wsl --install -d Ubuntu

Go in Ubuntu:

wsl -l -v
wsl -d Ubuntu

From there, install docker:

sudo apt-get update
 
sudo apt-get -y install apt-transport-https ca-certificates curl gnupg lsb-release
 
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
 
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
 
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
sudo groupadd docker
sudo usermod -aG docker $USER

To start:

sudo service docker start

To automatically start at startup, add at the end of the file:

vi ~/.bashrc
if (! pgrep dockerd > /dev/null); then
    sudo service docker start
fi

And also in order to not require a password for the above command, add to the end:

sudo visudo
your-username ALL=(ALL) NOPASSWD: /usr/sbin/service docker start

Now you can run wsl docker commands.
To get rid of the wsl prefix save this as docker.bat in C:\Windows:

docker.bat
@echo off
wsl docker %*
docker/install-docker-for-windows-wsl.1725661940.txt.gz · Last modified: 2024/09/07 01:32 by odefta