Skip to content

Instantly share code, notes, and snippets.

@derrickrobb
Last active May 27, 2019 16:08
Show Gist options
  • Select an option

  • Save derrickrobb/0ac2726711ddf6c1366ad278afcaab9e to your computer and use it in GitHub Desktop.

Select an option

Save derrickrobb/0ac2726711ddf6c1366ad278afcaab9e to your computer and use it in GitHub Desktop.
WSL Docker Setup

This guide is based off of Setting Up Docker for Windows and WSL to Work Flawlessly

This will disable VirtualBox when you enable Hyper-V

Install Docker for Windows Sub-system Linux

# 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

Install Docker Compose

# Install Python and PIP.
sudo apt-get install -y python python-pip

# Install Docker Compose into your user's home directory.
pip install --user docker-compose

Configure WSL to Connect to Docker for Windows

Turn on "Expose Daemon on tcp://localhost:2375 without TLS" in Docker Desktop(Windows)

Setup WSL Docker to connect to the windows daemon

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

Ensure everything is bueno

# You should get a bunch of output about your Docker daemon.
# If you get a permission denied error, close + open your terminal and try again.
docker info

# You should get back your Docker Compose version.
docker-compose --version

Volume Mounts.. >:(

OPTIONAL - Upgrade to Ubuntu 18.04 - I can only confirm that this works on 18.04, My guess is 16.04 works fine.

# Install release upgrader
sudo apt install ubuntu-release-upgrader-core -y

# Upgrade! (20-30 min wait time)
sudo do-release-upgrade -d

We need to set root = / because this will make your drives mounted at /c or /e instead of /mnt/c or /mnt/e.

The options = "metadata" line is not necessary but it will fix folder and file permissions on WSL mounts so everything isn’t 777 all the time within the WSL mounts. I highly recommend you do this!

sudo vi /etc/wsl.conf

# Now make it look like this and save the file when you're done:
[automount]
root = /
options = "metadata"

After making this change sign out of your computer so it will recognize the changes.

Enable C: Sharing

If you try to enable the C: for sharing at this moment it will most likely give you a firewall error.

Open PowerShell as Administrator then run:

Set-NetConnectionProfile -interfacealias "vEthernet (DockerNAT)" -NetworkCategory Private

Go to your network settings:

Win + X

Select "Network Connections" -> "Network and Sharing Center" -> "Change Adapter Settings"

Select "vEthernet (DockerNAT)" -> Properties

Unselect File and Printer Sharing and press OK then open the properties again and turn it back on. (windows magic ensues)

Go to Docker Desktop and share your C:

HOOORAY it should work, otherwise book off the next couple hours

Troubleshooting

Error starting userland proxy: mkdir /port/tcp:0.0.0.0:80:tcp:172.19.0.3:80: input/output error

Restart your docker daemon through Docker Desktop

Volume showing directories but not files

This means your mount of C: was unsuccessful, check your root directory to see if C exists. If C: exists be sure it is shared in Docker Desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment