To use Docker with WSL2, you should have WSL2 installed. You can list your installed Linux distributions and check the version of WSL each is set to by entering below command in PowerShell or Windows Command Prompt.
After installation, start a new WSL2 session and you will be asked to create a User Name and Password for your Linux distribution. Follow the prompt for instructions.
Update software packages.
sudo apt update && sudo apt upgrade
Install Docker dependencies.
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl gnupg2
Switch the firewall to legacy iptables.
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
If you receive error "update-alternatives: error: no alternatives for iptables". Run below commands to install iptables first. Then retry above step.
sudo apt update
sudo apt install iptables
Download the Docker OpenPGP signing key for your distribution.
. /etc/os-release
curl -fsSL https://download.docker.com/linux/${ID}/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker package repository to /etc/apt/sources.list.d.
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" \
| sudo tee /etc/apt/sources.list.d/docker.list
Install Docker.
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Add the current user to the docker group.
sudo usermod -aG docker $USER
Restart the WSL2 session by closing and reopening your WSL2 terminal to apply group changes.
Start Docker Daemon.
In a MATLAB command window, confirm that MATLAB detects your Docker installation.
[~,msg] = system('wsl docker version')