How to fix Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: connect: no such file or directory in Docker

DockerBEGINNERMEDIUMUpdated Dec 1, 2025· 311 views

This error occurs when the Docker daemon is not running or the socket file does not exist. The Docker CLI cannot communicate with the daemon because the Unix socket at /var/run/docker.sock is missing.

Quick fix

Fixes Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: connect: no such file or directory

sudo systemctl status docker
  1. Check if Docker daemon is running
  2. Start the Docker daemon
  3. Enable Docker to start at boot
  4. Unmask Docker service if masked
docker — error
sudo systemctl status docker
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: connect: no such file or directory

What this error means

When you run a Docker command, the Docker CLI needs to communicate with the Docker daemon. On Linux and macOS, this communication happens through a Unix socket located at `/var/run/docker.sock`. This socket file is created by the Docker daemon when it starts. The "no such file or directory" error for docker.sock means the socket file literally does not exist on your system. This is different from permission denied errors where the socket exists but you lack access rights. Without this socket file, the Docker CLI has no way to connect to the daemon. The most common reason is that the Docker daemon (dockerd) is not running. The daemon creates the socket when it starts and removes it when it stops. Other causes include Docker not being installed correctly, the daemon being configured to use a different socket location, or the socket being accidentally deleted.

Typical symptoms

  • Docker commands fail with 'connect: no such file or directory' message
  • Running 'ls -la /var/run/docker.sock' shows the file does not exist
  • Error message includes 'unix:///var/run/docker.sock'
  • Docker CLI commands hang then fail with connection error
  • Docker Compose fails to start services with socket errors
  • CI/CD pipelines fail at Docker build or run steps

Common causes

  1. Docker daemon (dockerd) is not running (most common)
  2. Docker service failed to start at boot
  3. Docker was installed but the system was not restarted
  4. Docker Desktop is not running (macOS/Windows)
  5. Docker daemon is configured to use a different socket path
  6. Snap installation of Docker conflicts with apt installation
  7. Docker was uninstalled but some tools still reference it
  8. WSL integration is not enabled in Docker Desktop
  9. Systemd service for Docker is masked or disabled

How to fix "Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: connect: no such file or directory"

1Check if Docker daemon is running

First, verify whether the Docker daemon is actually running:

On systems with systemd (most modern Linux):

bash
sudo systemctl status docker

Look for "Active: active (running)". If it shows "inactive" or "failed", the daemon is not running.

Alternative check:

bash
ps aux | grep dockerd

If you see a dockerd process, the daemon is running but might be using a different socket.

2Start the Docker daemon

If Docker is not running, start the service:

Using systemctl (recommended):

bash
sudo systemctl start docker

Using service command (older systems):

bash
sudo service docker start

Verify it started:

bash
sudo systemctl status docker

The socket file should now exist:

bash
ls -la /var/run/docker.sock
3Enable Docker to start at boot

To prevent this issue after reboots, enable the Docker service:

bash
sudo systemctl enable docker

This creates the necessary symlinks for systemd to start Docker automatically.

Verify it's enabled:

bash
sudo systemctl is-enabled docker

Should output "enabled".

4Unmask Docker service if masked

Sometimes the Docker service gets "masked", preventing it from starting:

Check if masked:

bash
sudo systemctl status docker

If you see "Loaded: masked", run:

bash
sudo systemctl unmask docker.service
sudo systemctl unmask docker.socket
sudo systemctl start docker

This situation can occur after certain system updates or when Docker was previously disabled intentionally.

5Start Docker Desktop (macOS/Windows)

If you're using Docker Desktop on macOS or Windows:

macOS:
1. Open Finder and go to Applications
2. Double-click "Docker" to launch Docker Desktop
3. Wait for the whale icon in the menu bar to stop animating

Windows:
1. Click Start menu and search for "Docker Desktop"
2. Launch the application
3. Wait for the whale icon in the system tray to become stable

Enable default socket (Docker Desktop):
1. Open Docker Desktop Settings
2. Go to Advanced
3. Enable "Allow the default Docker socket to be used"
4. Click "Apply & Restart"

6Configure WSL integration (Windows)

If using Docker Desktop with WSL on Windows, ensure integration is enabled:

1. Open Docker Desktop
2. Go to Settings > Resources > WSL Integration
3. Enable integration for your Linux distribution
4. Click "Apply & Restart"

Inside WSL, verify the socket:

bash
ls -la /var/run/docker.sock

If the socket is still missing, restart WSL:

powershell
# In PowerShell (not WSL)
wsl --shutdown

Then reopen your WSL terminal and try again.

7Check DOCKER_HOST environment variable

If Docker is configured to use a different socket, the default location won't have a socket:

bash
echo $DOCKER_HOST

If this shows a value like tcp://localhost:2375 or a different socket path, either:

Option 1: Unset to use default socket:

bash
unset DOCKER_HOST
docker info

Option 2: Point to the actual socket location:

bash
# Find where Docker is listening
sudo find / -name "docker.sock" 2>/dev/null

Common alternative locations:
- /run/docker.sock
- ~/.docker/run/docker.sock
- /var/run/docker/docker.sock

8Resolve Snap vs apt conflicts

If you have both Snap and apt versions of Docker installed, they can conflict:

Check for Snap Docker:

bash
snap list | grep docker

Check for apt Docker:

bash
dpkg -l | grep docker

If both are present, remove one:

Remove Snap Docker:

bash
sudo snap remove docker

Or remove apt Docker:

bash
sudo apt remove docker docker-engine docker.io containerd runc

Then restart your system and reinstall Docker using your preferred method.

9Install or reinstall Docker

If Docker is not properly installed, install it:

Ubuntu/Debian:

bash
# Remove old versions
sudo apt remove docker docker-engine docker.io containerd runc

# Add Docker repository
sudo apt update
sudo apt install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start and enable
sudo systemctl start docker
sudo systemctl enable docker

After installation, log out and back in, or restart your system.

Advanced notes

Socket file locations by platform:
- Linux (default): /var/run/docker.sock
- macOS Docker Desktop: /var/run/docker.sock (symlink to ~/.docker/run/docker.sock)
- Windows Docker Desktop: Uses named pipe //./pipe/docker_engine (socket available in WSL)

Rootless Docker:
If you've set up rootless Docker, the socket is at a different location:

bash
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock

Checking daemon logs:

bash
sudo journalctl -u docker.service -e

This shows recent Docker daemon logs and can reveal why it failed to start.

Docker context issues:
Modern Docker supports contexts that can point to different daemons:

bash
docker context ls
docker context inspect default

If the current context points to a non-existent socket, switch contexts:

bash
docker context use default

systemd socket activation:
Docker can use socket activation where systemd manages the socket:

bash
sudo systemctl start docker.socket

This creates the socket and starts the daemon on first connection.

SELinux/AppArmor:
On systems with SELinux or AppArmor, security policies might prevent socket creation. Check:

bash
# SELinux
sudo ausearch -m avc -ts recent | grep docker

# AppArmor
sudo aa-status | grep docker

Frequently asked questions

What does "Got permission denied while trying to connect to the Docker daemon soc" mean?
When you run a Docker command, the Docker CLI needs to communicate with the Docker daemon. sock. This socket file is created by the Docker daemon when it starts.
How do I fix "Got permission denied while trying to connect to the Docker daemon soc"?
This error occurs when the Docker daemon is not running or the socket file does not exist. The Docker CLI cannot communicate with the daemon because the Unix socket at /var/run/docker.sock is missing.
What causes "Got permission denied while trying to connect to the Docker daemon soc"?
Docker daemon (dockerd) is not running (most common) Docker service failed to start at boot Docker was installed but the system was not restarted
Is the "Got permission denied while trying to connect to the Docker daemon soc" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading