Summary

Short practical guide showing how to enable Docker WSL integration so that Docker Desktop (running in one WSL instance) is accessible from other WSL instances without installing Docker in each one. The solution: enable WSL integration in Docker Desktop settings, which mounts the Docker socket at /var/run/docker.sock.

簡短實用指南,說明如何啟用 Docker WSL 整合,讓 Docker Desktop(在一個 WSL 實例中運行)可從其他 WSL 實例訪問,而無需在每個實例中安裝 Docker。

Key Points

  • Enable “WSL integration” in Docker Desktop → Resources → WSL Integration
  • This mounts docker.sock, docker-desktop-proxy.pid, docker-cli.sock in /var/run/ of integrated WSL instances
  • Without integration, Docker commands fail in non-Docker WSL instances
  • May need sudo for build commands due to Linux file permissions
  • Alternative (without Docker Desktop): manually mount docker.sock via bind mount

Insights

This is a narrow but commonly-encountered configuration issue when using WSL2 in development. The socket mounting approach is the same pattern used in CI/CD systems (mounting the Docker socket into a container to enable DinD — Docker-in-Docker equivalents). Understanding that Docker Desktop acts as a centralized socket server for all WSL instances clarifies why installation in each WSL is unnecessary.

Connections

Raw Excerpt

Enable WSL integration is the simplest […] This will mount the docker sock which you can verify in the non-docker machine by going to /var/run where you will find docker.sock files.