Setup Docker to run on Windows 11 & Ubuntu WSL2 AND still be able to use Docker Desktop to monitor the lot!!
The goal here is to set up a container cluster using WSL2, Ubuntu Linux, and other Open Source packages. The secondary goal being to be able to use it from both Linux and Windows AND to be able to still use Docker Desktop under either Windows or Linux to manage things.
To do so, we need to setup WSL2, Ubuntu, dockerd and containterd, then build docker-cli for Windows and finally wire them all together so they can talk to each other.
First you need to set up Windows so that you can use virtualised containers, as well as WSL2. Type the following in a terminal:
Enable-WindowsOptionalFeature -Online -FeatureName 'Containers' -All
Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V' -All
Enable-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform' -All
Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Windows-Subsystem-Linux' -All
To install software, we'll use winget
- the package manager for Windows. This is the easiest way to install stuff on Windows these days and ensure it remains up to date.
We'll be using the console a lot - so if you're not already using Windows Terminal, it's time you started doing so. You can get it from the Microsoft Store.
Note: Windows Terminal requires Windows 10 1903 (build 18362) or later
Now that we have the basics up and running, you should install Powershell if you don't already have it:
winget install --id 'Microsoft.Powershell' --scope machine
If you don't already have a copy of Ubuntu Linux installed under WSL2, type the following command in your console:
winget install Canonical.Ubuntu
If you DO already have a copy of Ubuntu Linux inxtalled under WSL2, type the following command to make sure you're up-to-date:
wsl.exe --update
Once it's installed, type:
ubuntu
You will see the message:
Installing, this may take a few minutes
Once it finishes, you must create a default account. You can use whatever username you like; I usually use my moniker 'Ragdata' and a password which is relatively easy to remember.
NOTE: You will only be able to install GUI Support for Ubuntu on WSL2 if you can find your graphics card listed HERE
- Install GCC if you haven't already:
sudo apt install gcc -y
- Install CUDA-Keyring
sudo wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
- Update & Install CUDA
sudo apt update
sudo apt install cuda -y
- Install basic X11 applications:
sudo apt install x11-apps
Open a terminal window to WSL Ubuntu and start by upgrading everything that can be:
sudo apt update && sudo apt upgrade -y
- Install packages to allow apt to use a repository over https:
sudo apt install ca-certificates curl gnupg2 lsb-release -y
- Add Docker's official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Use the following command to set up the repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the
apt
package index and install the latest version of Docker Engine, containerd, and Docker Compose:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
Because docker needs to grant some hefty privileges to a non-root user, it's a good idea to set up one specifically for this task:
sudo adduser dockeruser
Then you need to grant that user Sudo privileges:
sudo usermod -aG sudo dockeruser
Finally, add this user to the docker
group:
sudo usermod -aG docker dockeruser
sudo mkdir /etc/docker/
sudo pico /etc/docker/daemon.json
Add the following contents:
{
"hosts": [ "tcp://0.0.0.0:" ],
"tls": false
}
You can launch dockerd
directly using the following command:
sudo dockerd
and stop it with CTRL-C
.
If you want to launch dockerd
in the background, use:
sudo dockerd &
and stop it with:
sudo pkill dockerd
If you haven't already installed it, install Docker Desktop under windows:
winget install -e --id Docker.DockerDesktop
-
Open Docker Desktop and click on Settings >> General and check the box next to "Use the WSL2 based Engine"
-
Still under Settings >> General, ensure that the last option in the list "Use Docker Compose V2" is checked
-
Still under Settings, click Resources >> WSL Integration; ensure that "Enable integration with my default WSL distro" is checked, and also make sure that you select your preferred default from the list below that option (should be Ubuntu-20.04)
-
Verify that Docker Engine is installed correctly:
sudo service docker start
sudo docker run hello-world