Azure IoT Edge on Windows Subsystem for Linux (WSL)

If you try to run the Azure IoT Edge Runtime or the Azure IoT Edge Dev Tool on Windows Subsystem for Linux (WSL), then you will run into the following errors:

ERROR: Could not login to Container Registry. Please verify your credentials in CONTAINER_REGISTRY_ environment variables. 
If you are using WSL, then please set DOCKER_HOST Environment Variable. See the projects readme for full instructions.
('Connection aborted.', error(2, 'No such file or directory'))
ERROR: Could not connect to docker daemon.
ERROR: Docker is unavailable
CRITICAL: IoT Edge dependency not available: docker

Here’s how to fix that:

  1. Do not install Docker in WSL, you can use Docker on your Windows machine by modifying the path.
  2. In Docker Settings/General, Check “Expose Daemon on tcp:// without TLS”
  3. Execute the following in a Bash terminal. This will make docker available in your Bash terminal.
echo "PATH=\"$PATH:$HOME/bin:$HOME/.local/bin:/mnt/c/Program\ Files/Docker/Docker/resources/bin\"" >> ~/.bashrc
echo "alias docker=docker.exe" >> ~/.bashrc
echo "alias docker-machine=docker-machine.exe" >> ~/.bashrc
echo "alias docker-compose=docker-compose.exe" >> ~/.bashrc
echo "export DOCKER_HOST='tcp://localhost:2375'" >> ~/.bashrc
source ~/.bashrc

sudo sh -c "echo Defaults  env_keep += \"DOCKER_HOST\" >> /etc/sudoers.d/docker"

This will add Docker to your PATH, create aliases for the docker*.exe files and create a sudoers file so you don’t have to pass -E into the command every time you run it.

Let me know if you run into any issues.

Jon