Title: How to Fix the “Permission Denied” Error in Docker on Ubuntu

Author: Dominykas Jasiulionis
Published: April 9, 2025

Docker is a widely-used platform for deploying applications in lightweight containers. However, many users encounter a frustrating issue when trying to run Docker commands without superuser privileges: the dreaded “permission denied” error.

For example, running:

docker ps

might return:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

This happens because the Docker daemon runs as a root-owned service and communicates through a Unix socket. If your user doesn’t have the right permissions to access this socket, Docker commands will fail.

In this guide, we’ll walk you through simple steps to resolve this error on an Ubuntu-based VPS so you can use Docker without needing sudo every time.

Prerequisites

Before getting started, ensure the following:

– Docker is installed on your system. If not, follow this guide to install Docker on Ubuntu.
– You have administrative (sudo) access to your VPS.

How to Fix Docker Permission Denied Errors

1. Confirm Docker is Installed

First, verify Docker is installed by running:

docker –version

If Docker is installed, you’ll see output like:

Docker version 28.0.2, build 0442a73

If you get a “command not found” error, Docker is likely not installed. Reinstall it before proceeding.

2. Add Your User to the Docker Group

By default, Docker commands require root access. To run them as a regular user, add your user to the docker group:

sudo usermod -aG docker $USER

After running the command, log out and log back in, or use:

newgrp docker

To confirm your user is in the docker group, run:

groups

Now try:

docker ps

If it works without sudo, the issue is resolved.

3. Fix File and Directory Permissions

If you’re using Docker volumes or shared directories, permission issues may arise from file ownership. To fix this, change the ownership of the relevant directory:

sudo chown -R $USER:$USER /path/to/your/files

You might also need to adjust permissions:

chmod -R 750 /path/to/your/files

This grants full access to the owner, read/execute to the group, and denies access to others — a secure default for most cases.

4. Check Docker Socket Permissions

Docker uses a Unix socket located at:

/var/run/docker.sock

To check its permissions, run:

ls -l /var/run/docker.sock

You should see something like:

srw-rw—- 1 root docker 0 2025-04-05 07:55 /var/run/docker.sock

This means only root and docker group members can access it. While it’s possible to make the socket globally accessible with:

sudo chmod 666 /var/run/docker.sock

This is a major security risk and not recommended. Instead, stick to adding your user to the docker group.

5. Restart Docker and Test

After making these changes, restart the Docker service:

sudo systemctl restart docker

Or, on older systems:

sudo service docker restart

Then test your setup with:

docker run hello-world

If the container runs without errors, your permissions are correctly configured.

Conclusion

Fixing the Docker “permission denied” error on Ubuntu is straightforward if you follow these steps:

– Confirm Docker is installed.
– Add your user to the docker group.
– Adjust file and directory ownership and permissions.
– Verify Docker socket access.
– Restart Docker and test with a simple container.

Once done, you should be able to run Docker commands without sudo. If issues persist, double-check each step or consult a system administrator.

Frequently Asked Questions

Why does the “permission denied” error occur in Docker?

This typically happens when a non-root user tries to access the Docker daemon without being in the docker group.

Is it safe to change Docker socket permissions?

No. Setting overly permissive permissions (like 777) on the Docker socket can expose your system to security risks. Always prefer adding users to the docker group.

Do I need to restart my VPS?

No, a full restart isn’t necessary. Logging out and back in will apply group changes. Restarting the Docker service is usually enough.

About the Author

Dominykas Jasiulionis is a Technical Content Writer with a background in cloud engineering and technical support. He’s worked in fintech and point-of-sale industries and is passionate about DevOps, software development, and AI. Connect with him on LinkedIn.

Similar Posts