Skip to content

Instantly share code, notes, and snippets.

Last active January 21, 2023 17:12
  • Star 11 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Windows 10 Subsystem for Linux combined with Docker for Windows

Using Windows Subsystem for Linux combined with Docker for Windows

Docker CE for Windows

  • Install Docker CE for Windows
  • Go to Docker for Windows Settings -> General and enable Expose daemon on tcp://localhost:2375 without TLS.
    This will enable the Docker remote API for requests, coming from localhost, not from another computer in your network. A TLS secured version is not yet supported in Docker for Windows. See docker/for-win#453 for more information. I also tried a daemon.json file with options tlscacert, tlscert, tlskey and tlsverify, but Docker for Windows crashed on booting.

Install Windows Subsystem for Linux (WSL)

  • Enable Developer Mode as described in Enable your device for development
  • Install WSL by running the following in Powershell as Administrator: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux or read the Installation Guide
  • Reboot your computer
  • Open Windows search bar and type bash and you will find Bash on Ubuntu on Windows
  • Open it and you can start writing your bash commands

Download Docker Client

To be able to run Docker command, we need the Docker Client CLI in our WSL environment.
You find a script below, to download and setup Docker CLI and Docker Compose.
You can run it directly by executing the following:

sh -c "$(curl -sSL"

Content of the script:

  • It downloads the Docker binaries from
  • It extracts the docker executable (CLI client) from the tgz file and saves it under '/usr/local/bin/docker'.
  • It downloads bash completion
  • It adds the environment variable DOCKER_HOST=localhost:2375 to the ~/.bash_aliases file. Now Docker CLI knows that it should speak to the docker server on localhost:2375, which you enabled in Docker for Windows before.
  • It adds a rule to switch to /c when bash is started in /mnt/c
  • It adds a symbolic link, so that /c resolves to /mnt/c. By default you use /mnt/c in WSL to access your c drive. Now you can also use /c, which is the same behaviour, Docker for Windows uses, when you work with Docker volumes.

Bash from explorer context menu

To be able to start the WSL bash from the Windows explorer context menu, save 3-bash-context-menu.reg (see below) to a file and execute it by double click. Now you can open a WSL bash by right clicking in an explorer directory.

set -e
# Docker Version
# Docker Compose Version
# Download Docker CLI and Compose
mkdir -v --parents $DIR
curl$DOCKERVERSION.tgz | tar xvz --directory $DIR
mv -v $DIR/docker/docker /usr/local/bin/docker
chmod +x /usr/local/bin/docker
curl -L$COMPOSEVERSION/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
rm -vR $DIR
# Install bash completion
sudo curl -L -o /etc/bash_completion.d/docker
sudo curl -L$COMPOSEVERSION/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
# Set DOCKER_HOST variable in .bash_aliases
tee --append ~/.bash_aliases <<'EOF' > /dev/null
# set Docker remote
export DOCKER_HOST=localhost:2375
# switch to /c when starting bash in /mnt/c
if [[ $PWD == "/mnt/c"* ]]; then
DIR=$(echo $DIR | cut -d '/' -f3-)
cd "/"$DIR
# add symbolic link, so that /c resolves to /mnt/c
sudo ln -s /mnt/c /c
Windows Registry Editor Version 5.00
@="Open WSL Bash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment