How to Fix Docker Permission Denied Error on Ubuntu
Going through the error related to Docker permission in Ubuntu then you are at the right place. We have got the solution for the “Fix Docker Permission Denied” error on Ubuntu. The “Permission Denied” error in Docker on Ubuntu usually happens because the user doesn’t have proper access to the Docker daemon. The most straightforward solution is to add your user to the Docker group, but if that doesn’t work, there may be other configuration or service issues causing the problem.
How to Fix Docker Permission Denied Error on Ubuntu (Step-by-Step Guide)
If you’re using Docker on Ubuntu, encountering a “Permission Denied” error is a common issue, especially when running commands like docker run or docker-compose. This error occurs because your user doesn’t have the necessary permissions to interact with Docker.
In this guide, we’ll walk you through how to resolve this error, explaining each step in simple terms.
1. Reason Behind The Docker Permission Denied Error
Docker runs as the root user by default, which means that only the root user or users with special permissions (like those in the docker group) can interact with Docker commands. If your user isn’t in the Docker group, you’ll run into the “Permission Denied” error. When you run Docker commands, the system checks if your user is part of the Docker group or has root privileges. If neither is the case, Docker denies access.
2. Check Docker Installation
Before troubleshooting permissions, confirm that Docker is installed on your system:
Check Docker Version:
Open a terminal and run:
docker --version
This will show the version of Docker installed. If Docker is not installed, follow the installation steps below.
Install Docker (if necessary):
If Docker isn’t installed, follow these steps:
sudo apt-get update
Install Docker:
sudo apt-get install docker.io
Start the Docker service:
sudo systemctl start docker
Enable Docker to start at boot:
sudo systemctl enable docker
Verify Docker is running:
sudo systemctl status docker
Once Docker is installed and running, proceed to the next step.
3. Check the Permission Denied Error
Now, try running a simple Docker command to check for permission issues:
docker run hello-world
If you see a “Permission Denied” error, this confirms that your user doesn’t have the necessary permissions to interact with Docker.
4. Add Your User to the Docker Group
The most common fix is to add your user to the docker group. The Docker group grants the necessary permissions to interact with Docker commands without needing root access.
Add your user to the Docker group by running:
sudo usermod -aG docker $USER
This adds the current user ($USER) to the docker group. The -aG flag means “append to group.”
After running the command, log out and log back in to apply the changes. Alternatively, you can run:
newgrp docker
Verify that your user is part of the Docker group:
groups $USER
You should see docker listed among the groups.
5. Test the Docker Command Again
After logging back in (or running newgrp docker), test Docker again:
docker run hello-world
Now, you should be able to run the command without the “Permission Denied” error.
6. Ensure the Docker Service is Running
In some cases, the Docker service might not be running, which could also trigger a permission error. To check the status of Docker:
Run:
sudo systemctl status docker
If the service is inactive, start it with:
sudo systemctl start docker
To ensure Docker starts automatically on boot, run:
sudo systemctl enable docker
7. Check Docker Socket Permissions
If you’re still facing the “Permission Denied” error, it could be due to the permissions of the Docker socket file (/var/run/docker.sock).
The socket file is used by Docker to allow communication between the Docker client and the Docker daemon. If its permissions are incorrect, even users in the Docker group may face issues.
Check the socket permissions:
ls -l /var/run/docker.sock
You should see something like this:
srw-rw---- 1 root docker 0 Sep 21 15:00 /var/run/docker.sock
The docker group should have read and write permissions.
If the permissions are incorrect, you can fix them with:
sudo chown root:docker /var/run/docker.sock
Restart Docker to apply the changes:
sudo systemctl restart docker
8. Check AppArmor or SELinux (Advanced)
If you’re still encountering permission issues, it might be due to security modules like AppArmor (on Ubuntu) or SELinux (on other distributions). These modules can sometimes block Docker from running.
This is an advanced step, and you may not need to do it, but if all else fails, here’s what you can try:
For AppArmor:
Set Docker to run in a more permissive profile:
sudo aa-complain /etc/apparmor.d/docker
For SELinux (on non-Ubuntu systems):
You can temporarily set SELinux to permissive mode:
sudo setenforce 0
9. Reboot Your System (If Needed)
If none of the above steps resolved the issue, try rebooting your system to ensure all changes take effect properly.
sudo reboot