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 https://github.com/docker/for-win/issues/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-Linuxor read the Installation Guide
- Reboot your computer
- Open Windows search bar and type
bashand 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 https://gist.githubusercontent.com/kekru/0d14eb363260df78d012c901b94a19be/raw/2-install-docker-client.sh)"
Content of the script:
- It downloads the Docker binaries from https://download.docker.com/linux/static/edge/x86_64/
- 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:2375to 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.