The Error Scenario
You’ve just finished configuring your .devcontainer and you’re ready to dive into code. You click the blue "Reopen in Container" button, expecting a seamless transition. Instead, the progress bar stalls and a terminal error abruptly terminates the build process.
A quick look at the logs reveals the culprit:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
This roadblock is most common on Linux distributions like Ubuntu or for Windows developers using WSL2. It effectively means VS Code is trying to communicate with Docker through a local pipe (the Unix socket), but the connection is being refused or the pipe is locked down.
Analysis: Why is this happening?
Usually, the issue boils down to one of three common configuration gaps:
- The Service is Offline: The Docker background process (the daemon) simply isn't running on your host machine.
- The "Gatekeeper" Problem: Your user account lacks the permission to read or write to
/var/run/docker.sock. By default, this socket is owned byroot. - WSL2 Bridge Failure: On Windows, Docker Desktop might not be authorized to share its engine with your specific WSL2 Linux distribution.
Step 1: Verify the Docker Daemon Status
Before diving into complex permission fixes, ensure the engine is actually powered on. Run this command in your terminal:
sudo systemctl status docker
If the output shows inactive (dead), fire it up. Use the following commands to start the service and ensure it launches automatically every time you boot your computer:
sudo systemctl start docker
sudo systemctl enable docker
Step 2: Add Your User to the Docker Group
On Linux, Docker requires root privileges. Rather than prefixing every command with sudo, the standard practice is to join the docker group. This gives VS Code the "keys" it needs to access the socket.
- Create the docker group if it doesn't already exist:
sudo groupadd docker
- Add your current user (`$USER`) to this group:
```
sudo usermod -aG docker $USER
- Important: Group changes don't apply to active sessions. You must log out of your OS and log back in. If you are using WSL2, run
wsl --shutdownin a Windows PowerShell window to force a reset.
Need a temporary fix without logging out? Run newgrp docker in your terminal. This only affects that specific terminal tab, so a full restart is still better for VS Code stability.
Step 3: Adjust Socket Permissions (The Quick Workaround)
If group membership doesn't resolve the issue immediately, you can manually open the socket permissions. While this is slightly less secure on multi-user systems, it is a highly effective fix for local development environments.
sudo chmod 666 /var/run/docker.sock
This command grants read and write access to all users. Note that some system updates or Docker restarts might revert this file back to its default 660 permission level.
Step 4: Configure WSL2 Integration on Windows
Windows users often see this error when Docker Desktop is running but isn't "talking" to the Linux subsystem.
- Open the Docker Desktop dashboard.
- Navigate to Settings (the gear icon) > Resources > WSL Integration.
- Verify that "Enable integration with my default WSL distro" is toggled on.
- Find your specific distro (e.g., "Ubuntu-22.04") in the list and flip the switch to On.
- Click Apply & Restart.
Step 5: Check VS Code Path Settings
Occasionally, VS Code looks for the Docker executable in the wrong directory. Open your settings (Ctrl + ,) and search for docker.path. Ensure the "Dev Containers: Docker Path" field is either empty (defaulting to docker) or points to the valid path of your Docker binary.
Verification: Confirm the Fix
To confirm everything is working, open a fresh terminal and run:
docker ps
If you see a clean table with headers like CONTAINER ID and IMAGE without using sudo, you’ve succeeded. Head back to VS Code and click "Try Again." Your Dev Container should now pull the base image and start building without further complaints.

