Dev tools

Docker Permission Denied: Causes and Safe Fixes

Docker permission denied usually means your user can't reach the Docker socket or a volume's owner doesn't match. Find the cause and fix it safely.

By OmniAI Editorial · Nov 21, 2026 · 12 min read

A "docker permission denied" error almost always has one of two causes: your user account can't open the Docker daemon's socket, or a process inside a container can't read or write a file because the file's owner doesn't match the container's user. The first is fixed by giving your user access to the socket (the docker group or rootless Docker), the second by matching user IDs or ownership between the host and the container. Changing the socket to world-writable with chmod 666 makes the error go away, but it hands root-level control of the machine to every local user, so don't do it.

This guide shows how to tell which permission problem you have, how to fix each one safely, and how to avoid the error in the first place. The commands come from Docker's own documentation for Linux; Docker Desktop on Mac and Windows handles the socket for you, so most of this applies to Linux servers, VPSes and WSL setups.

What the Docker Permission Denied Error Means

The Docker command-line tool (docker) doesn't run containers itself. It sends requests to the Docker daemon (dockerd) over a Unix socket, by default /var/run/docker.sock. Docker's documentation explains that when the daemon starts, it creates this socket and makes it accessible to the root user and to members of the docker group. Any other user gets refused by the operating system before Docker even sees the request.

That gives you two very different families of the docker permission denied error:

  • Client to daemon: your shell user can't open the socket. Every docker command fails, even docker ps.
  • Inside the container: the container starts, but its process can't touch a file or folder, usually one you mounted from the host.

There's also a third, smaller group: errors about your own Docker config folder (~/.docker), and errors from the build step. The table below maps the messages you'll see to their cause.

Error message (shortened)Where it happensUsual causeFix
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockAny docker commandYour user isn't in the docker group, or the group change hasn't taken effectAdd the user to the docker group and start a new session, or use rootless Docker
Cannot connect to the Docker daemon at unix:///var/run/docker.sockAny docker commandThe daemon isn't running (not a permission problem, but often confused with one)Start or restart the Docker service
WARNING: Error loading config file: /home/user/.docker/config.json ... permission deniedAny docker command~/.docker was created by an earlier sudo docker run and is owned by rootFix the folder's ownership
Permission denied when the app writes to /data (or similar)Inside the containerThe mounted host folder is owned by a different user ID than the container processMatch UIDs, fix ownership, or use a named volume
Permission denied on a mounted folder on Fedora, RHEL or CentOSInside the containerSELinux blocks the container from the host folderAdd the :z or :Z label option to the bind mount
COPY failed or permission denied during docker buildBuild stepThe files can't be read by the build, or are excludedCheck file permissions and .dockerignore
A grey person shape, an ink arrow to an orange ring, and another ink arrow to three stacked light server units with ink dots.
Every docker command goes through the daemon's socket; without access, the request stops there.

How to Diagnose Your Docker Permission Denied Error

Before changing anything, spend a minute finding out which case you're in. These checks are read-only.

systemctl status docker          # is the daemon running?
ls -l /var/run/docker.sock       # who owns the socket, and which group can use it?
id                               # which groups is your current session in?

If the daemon isn't running, start it with sudo systemctl start docker and try again. If the socket's group is docker and id doesn't list docker, you have the classic socket problem. If docker ps works but your container logs show Permission denied on a path, you have a file ownership problem inside the container. Run docker run --rm <image> id to see which user ID the image runs as, and ls -ln on the host folder to see its numeric owner.

Fix 1: docker.sock Permission Denied

The "docker.sock permission denied" message is the most common version of the error. In full, it reads like docker permission denied while trying to connect to the Docker daemon socket, followed by the socket path. You have three safe ways to fix it, and one unsafe one to avoid.

Option A: add your user to the docker group

This is the standard post-install step in Docker's Linux documentation:

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

The first command may report that the group already exists; that's fine. The newgrp docker command activates the new group in your current terminal. Other terminals and services only pick it up after you log out and back in (on some virtual machines you need a full restart). Then check with docker run hello-world.

Docker's documentation is blunt about the trade-off: the docker group grants root-level privileges to the user. Anyone who can talk to the daemon can start a container that mounts the host's root filesystem and change anything on it. On a single-user workstation that's usually acceptable. On a shared server it means "docker group" and "sudo access" are effectively the same thing, so only add trusted users.

Option B: rootless Docker

Rootless Docker runs the daemon and the containers as your normal user, so access to its socket no longer means access to root. Docker supports it officially. The setup, in short:

sudo apt-get install -y uidmap                        # provides newuidmap and newgidmap
dockerd-rootless-setuptool.sh install                 # run as your normal user, not root
export DOCKER_HOST=unix:///run/user/1000/docker.sock  # the installer prints your exact line

The installer also tells you how to control the service (systemctl --user start docker.service) and how to keep it running after logout (sudo loginctl enable-linger <user>). Rootless mode has limits worth knowing before you switch: by default containers can't bind to ports below 1024, some storage and networking options differ, and your user needs ranges in /etc/subuid and /etc/subgid. For many developer machines and small servers it's the cleanest fix. If you're weighing a daemonless alternative instead, our comparison of Docker vs Podman covers how Podman handles rootless containers by default.

Option C: use sudo only when you need it

Prefixing commands with sudo works and needs no setup. It's a reasonable choice on a server where only admins run Docker anyway. The downside is that it's easy to create root-owned files in your home folder, which leads straight to the next error.

What not to do: chmod 666 on the socket

Many forum answers suggest sudo chmod 666 /var/run/docker.sock. It removes the error by letting every user on the machine control Docker, which means every user can become root. The change also disappears when the daemon restarts, so people repeat it or script it. Use the docker group or rootless mode instead.

Fix 2: The ~/.docker Config Error

If you ran sudo docker ... before joining the docker group, Docker may have created ~/.docker owned by root. Afterwards you'll see a warning that config.json can't be loaded because of permission denied. Docker's documentation gives two fixes: delete the folder (it's recreated, but you lose saved settings and logins), or give it back to your user:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

Fix 3: Docker Volume Permission Denied

A "docker volume permission denied" error happens inside the container, and the docker group has nothing to do with it. Linux checks file access by numeric user ID (UID) and group ID (GID), not by name. If your host folder is owned by UID 1000 and the container's process runs as UID 999 (or as a non-root app user the image created), the process can't write to the mounted folder, even though both sides look correct by name.

Pick the fix that matches who should own the data.

Run the container as your host user. For development, this is often the quickest fix:

docker run --rm -u "$(id -u):$(id -g)" -v "$PWD/data:/data" alpine touch /data/test

In Docker Compose the same thing is the user: key on the service. It works when the image doesn't depend on running as a specific user.

Give the folder to the container's user. If the image always runs as a fixed UID (many official database images do), change the host folder's owner to that number, for example sudo chown -R 999:999 ./data. Check the image's documentation or run docker run --rm <image> id to find the right UID.

Build the image with a matching user. In your own Dockerfile, create the app user with a UID you choose (for example via a build argument) and chown the app folders during the build, so the runtime user owns what it needs to write.

Use a named volume instead of a bind mount. Named volumes (-v mydata:/data) are managed by Docker and live outside your project folder. By default, when an empty volume is mounted on a path that already has content in the image, Docker copies that content into the volume, so the folder starts out the way the image's author set it up, which avoids many mismatches. Bind mounts never do this; they show the host folder exactly as it is.

SELinux: the hidden cause

On Fedora, RHEL, CentOS and related systems, SELinux can deny access even when the UIDs and file modes are correct. Docker's bind mount documentation describes two label options: z means the content is shared among multiple containers, and Z means it's private to one container.

docker run -v "$PWD/data:/data:z" myimage

Docker warns to use extreme caution: relabeling a system directory such as /home or /usr with Z can make the host unusable. Only label folders you created for the container.

A light folder joined by an ink line with a small ring to a grey container with ink ribs, with an orange circle on the container's top right corner.
A bind mount shows the host folder as it is; if the user IDs differ, the container can't write.

Fix 4: Permission Denied During docker build

When docker build fails with permission denied on a COPY or RUN step, check three things. First, can the files be read by your user on the host (a root-owned file from an earlier sudo command is a common culprit)? Second, is the file excluded by .dockerignore, which makes COPY fail in confusing ways? Third, if a RUN step runs a script, is the script executable? Add RUN chmod +x script.sh or call it with sh script.sh.

Which Fix Should You Use?

Use this checklist to pick the right fix the first time:

  • Every docker command fails, socket error: you're on a personal machine, so add yourself to the docker group. On a shared server, use rootless Docker or keep using sudo.
  • "Cannot connect to the Docker daemon": start the service; permissions are fine.
  • Warnings about `~/.docker/config.json`: fix the folder's ownership.
  • Container can't write to a mounted folder: match the UID with -u, chown the folder to the image's UID, or switch to a named volume.
  • Same, on Fedora or RHEL: add :z to the mount.
  • Build fails: check file permissions, .dockerignore and execute bits.

How to Avoid Docker Permission Errors

Most docker permission denied errors come from a few habits that are easy to change:

  • Decide once how you run Docker on each machine (docker group, rootless or sudo) and stick to it, so you don't mix root-owned and user-owned files.
  • In your own images, run the app as a non-root user with a known UID, and document it in the README.
  • Prefer named volumes for databases and app data; use bind mounts for source code you edit on the host.
  • Keep host folders for bind mounts out of system paths.
  • On a small VPS that only you use, the docker group is usually fine; if you rent a cheap VPS and share it, set up rootless mode from the start.

If you're deciding how containers fit into a bigger setup, our guide to Docker vs Kubernetes explains where Kubernetes changes the picture: there, permissions are set per pod with security contexts rather than with the docker group.

FAQ

How do I fix docker permission denied without sudo?

To use Docker without sudo, add your user to the docker group with sudo usermod -aG docker $USER, then run newgrp docker or log out and back in. For a setup where Docker access doesn't equal root access, install rootless Docker instead. Both fixes are in Docker's official Linux post-install guide.

Is it safe to add my user to the docker group?

It's safe only for trusted users. Docker's documentation warns that the docker group grants root-level privileges, because a member can start a container that mounts and changes the host's files. On a personal laptop that's usually acceptable; on shared servers, prefer rootless Docker.

Why do I still get permission denied after adding myself to the docker group?

Group membership is read when you log in. Your current terminal doesn't know about the new group until you run newgrp docker or start a new login session; some systems need a full reboot. Check with id: if docker isn't listed, the change hasn't taken effect yet.

Why does my container get permission denied on a mounted volume?

The container process runs as a user ID that doesn't own the host folder. Linux compares numeric IDs, so names don't help. Run the container with -u $(id -u):$(id -g), change the folder's owner to the image's UID, or use a named volume. On SELinux systems, also add :z to the mount.

What does rootless Docker change?

Rootless Docker runs the daemon and containers under your own user account, so access to its socket doesn't give root on the host. The trade-offs are a few missing features, such as binding to ports below 1024 without extra setup, and a one-time setup with dockerd-rootless-setuptool.sh.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog