Containers can provide a quick way to spin up an app without having to worry about the backend OS. With Docker on WSL you can easily test multiple containers. Docker provides some great documentation, but it’s a little confusing to get it working with WSL.
Get Docker for Windows
Let’s head over to the Docker website to download the community edition for our Windows 10 machine. If you search “Docker CE for Windows” you should find the download link for this page Docker for Windows
(You’ll need to create a Docker hub account to download)
Install with the defaults (including the option to run Linux container.) Launch docker from the icon on your desktop. You’ll be prompted about installing Hyper-V. Hit okay to allow it to install. That will add the Hyper-V feature and reboot your system.
After you’ve installed Docker and enabled Hyper-V you need to set a feature in Docker to work with WSL. Find the Docker icon on the bottom right corner and right mouse-clike and choose Settings. Check the box next to “Expose Daemon”
We now have Docker running on our Windows 10 machine.
Prepare Ubuntu for Docker setup
We have Docker running on Windows so let’s get into WSL/Bash prompt to get it working on the Linux side.
Update apt package index:
sudo apt-get udpate
Install packages for docker: (copy and paste entire section)
sudo apt-get install apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Install Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify key from previous step:
sudo apt-key fingerprint 0EBFCD88
Setup the repository: (copy and paste entire section)
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Run Update Again:
sudo apt-get update
Install Docker CE
sudo apt-get install docker-ce
Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Set Permissions for binaries:
sudo chmod +x /usr/local/bin/docker-compose
Allow Docker to speak to host
We need to edit .bashrc
nano ~/.bashrc
Add the following line to the bottom of the file and save it
export DOCKER_HOST=tcp://localhost:2375
Reload .bashrc:
source ~/.bashrc
Allow Docker CLI access without root access
sudo usermod -aG docker $USER
Now, restart WSL and test your docker setup from WSL:
docker run hello-world
References:
https://docs.docker.com/install/linux/docker-ce/ubuntu/
https://docs.docker.com/compose/install/