Configure Docker for Windows
First, we need to expose a port in Docker for Windows
for it to work in WSL.
Install Docker
This is how you install Docker in your WSL environment - it is taken from Docker’s installation docs. Just copy and paste basically. This is for Ubuntu 18.04.
# Update the Apt Package List.
sudo apt-get update -y
# Install Docker's Package Dependencies.
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# Download and Add Docker's Official Public PGP Key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Verify the Fingerprint.
sudo apt-key fingerprint 0EBFCD88
# Add the `Stable` Channel's Docker Upstream Repository.
# # If You Want to Live on the Edge, You Can Change "Stable" Below to "Test" Or
# "Nightly". I Highly Recommend Sticking with Stable!
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# Update the Apt Package List (for the New Apt Repo).
sudo apt-get update -y
# Install the Latest Version of Docker CE.
sudo apt-get install -y docker-ce
# Allow Your User to Access the Docker CLI without Needing Root Access.
sudo usermod -aG docker $USER
After this, close and open a new terminal, so you can run Docker
without sudo.
Install Docker Compose
Installing Docker Compose can be done via PIP
or the normal apt-get
way.
# Install Python 3 and PIP.
sudo apt-get install -y python3 python3-pip
pip3 install --user docker-compose
# Or Install only Docker Compose
sudo apt-get install docker-compose
Add Bin to Your PATH
You need to add /home/<username>/.local/bin
to your PATH.
Edit your ~/.profile
file with nano ~/.profile
and add a new line anywhere in the file. Add the text export PATH="$PATH:$HOME/.local/bin"
Run source ~/.profile
to activate your new path.
Confirm that it works by running echo $PATH
.
Add DOCKER_HOST
You might need to export the following variable to make it work. You can write it either in ~/.zshrc
or in ~/.bashrc
.
export DOCKER_HOST=127.0.0.1:2375
Modify WSL Configurations
If you are running Windows 10 18.03+
or newer, it might be good to make some changes. sudo nano /etc/wsl.conf
to edit your configurations file.
[automount]
root = /
options = "metadata"
This will allow you to work from /c
instead of /mnt/c
, and also fixes some of your permissions. You need to sign out of Windows to make this work.