Install Docker on Windows Subsystem for Linux

From JMK Wiki
Jump to navigation Jump to search

Install Docker

Note: based on https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly.

Prerequisites

Install required packages:

root@localhost ~ # apt install curl apt-transport-https

Add the docker repository to the sources.list configuration:

root@localhost ~ # echo "deb https://download.docker.com/linux/debian stretch stable" > /etc/apt/sources.list.d/docker.list

Optionally the edge channel can be used for more recent version:

root@localhost ~ # echo "deb https://download.docker.com/linux/debian stretch edge" > /etc/apt/sources.list.d/docker.list

Download and add the private key for the repository:

root@localhost ~ # curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

Verify the private key:

root@localhost ~ # apt-key fingerprint 0EBFCD88

Update the list of available packages:

root@localhost ~ # apt update

Install Docker

Install docker:

root@localhost ~ # apt install docker-ce

Verify Docker version:

user@localhost ~ $ docker -v

Add the user to the docker group so no root privileges are needed to create and start containers (use the actual username instead of <USERNAME>):

root@localhost ~ # usermod -aG docker <USERNAME>

This will only take effect after the user logged out and then logged in again.

Set the docker host for the user:

user@localhost ~ $ echo "export DOCKER_HOST=tcp://127.0.0.1:2375" >> ~/.bashrc
user@localhost ~ $ source ~/.bashrc

Verify if docker works:

user@localhost ~ $ docker ps
user@localhost ~ $ docker run busybox uname -a

Install docker-compose

Like AWS CLI, docker compose can be installed from the Debian repository it is an outdated version and it is better to install via pip:

root@localhost ~ # pip install docker-compose

Verify docker-compose version:

user@localhost ~ $ docker-compose -v

Fix docker mount points

For a more detailed explanation visit https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly.

Windows 10 version 1803

root@localhost ~ # echo -e "[automount]\nroot = /\noptions = metadata" > /etc/wsl.conf

A WSL restart is required

Windows 10 version 1709

root@localhost ~ # mkdir /c
root@localhost ~ # mount --bind /mnt/c /c