Saltar a contenido

Docker in WSL

Since Docker Desktop for Windows cannot be installed anymore on corporate laptops, due to the new Community & Enterprise editions of Docker, here's the workaround to have Docker in your Windows mahcine, installed under the Windows Subsystem For Linux (WSL).

Prerequisites

  1. Turn on required features on Windows such as Hyper-V, virtualization and the Windows Subsystem for Linux.
  2. Install the Debian distro from the Microsoft Store (preferred, as other distro such as Ubuntu may have some issues during the Docker installation).
    • Once installed, open Debian terminal and follow the steps to setup your root username and password. Recommended: As you will need sudo quite often, set a simple remindable password, like a PIN, which is different from the dynamic CORP passsword.

Install Docker on WSL

  1. In case you just installed Debian, first restart the terminal.
  2. Follow step-by-step the official installation guide for Docker Engine (not Desktop) on Debian.
  3. Restart the terminal.
  4. Start Docker with one of the following commands:
    • Start using daemon:
      sudo dockerd
      
    • Start using service:
      sudo service docker start
      
  5. Once started, completely close the terminal session without running Ctrl+C out of the command. Docker service will still run in the background.
  6. Open the terminal and run docker ps to check if Docker is running.
  7. Add your user to the Docker group to run Docker commands as sudo:
    sudo usermod -aG docker <username>
    

Troubleshoot

Docker daemon failed to start due to iptables

Debian may change the WSL iptables definition and Docker may have failed during start up.

In order to fix this issue, run the following commands as recommended workaround by the community to restore the legacy iptables:

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

Now try starting Docker daemon again as described in the installation steps above.

Reinstall Docker Compose plugin latest version

For some specific Docker Compose modules, such as Docker on Azure ACI integration, you may need to reinstall the Docker Compose plugin:

  1. Uninstall the current Docker Compose Plugin.
    sudo apt-get remove docker-compose-plugin
    
  2. Install the Docker Compose CLI following this guide, or with the following automatic installation command:
    curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh
    
  3. Restart the terminal.
  4. Re-install the Docker Compose Plugin:
    sudo apt install docker-compose-plugin
    

For Docker Azure integration, try to login using a service principal (App Registration):

docker login azure --client-id <app-id> --client-secret <secret> --tenant-id <id>