Skip to content

Instantly share code, notes, and snippets.

@kalibek-epam
Last active April 16, 2024 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalibek-epam/fdcfe6dcd82fcc6bb10b7af3f3935f5e to your computer and use it in GitHub Desktop.
Save kalibek-epam/fdcfe6dcd82fcc6bb10b7af3f3935f5e to your computer and use it in GitHub Desktop.
Docker installation guide for WSL2 with Debian

Installation

Prerequisites

  • Windows 11, or Windows 10 version 1903 or higher, with Build 18362 or higher, for x64 systems, and Version 2004 or higher, with Build 19041 or higher, for ARM64 systems
  • Basic linux command line understanding
  • Optional: Windows terminal application

On host machine

  1. Enable wsl2 and install debian
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
wsl --set-default-version 2
wsl --inistall -d Debian
  1. Login into debian and create name and password for your user. To start wsl2 click windows button and type your distribution name and click on the icon

  2. Enable sudo priviliges for current linux user. In powershell (replace MY_USER with username you created on previous step):

wsl -d Debian --user root
usermod -aG sudo MY_USER

On linux machine

  1. Install docker from official manual or through installation script

  2. Change /etc/wsl.conf to allow mounting volumes from windows and autostarting docker

[boot]
command="service docker start"

[automount]
root=/
  1. Change /etc/docker/daemon.json inside to expose port for window installation
{"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}

Docker in commandline

  1. One of the options is to install docker-cli from chocolatey docker-cl

Testcontainers

In order to be able to run testcontainers tests it is required to add DOCKER_HOST environment variable that directs to WSL2 machine.

  1. Run command in Windows powershell to obtain ip of wsl2 machine
PS C:\Users\me> wsl hostname -I
172.23.200.48 172.17.0.1 172.30.0.1
  1. Set environment variable in windows to the first ip address DOCKER_HOST=tcp://172.23.200.48:2375

Limitations:

  1. Volume mounting from windows host requires providing paths in specific format.
    • in git bash. It is required leading slash / effectively making path to look like //c/some/dir. The command below will mount current directory to /data inside the container
    $ docker run --rm -ti -v /$(pwd):/data bash -c "ls -la /data"
    • in powershell. It is required to provide paths as :
    PS C:\projects\bash> docker run --rm -ti -v /c/projects/bash:/data bash -c "ls -la /data"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment