Intrduction
When setting up Docker on Ubuntu 24.04, you might encounter a "permission denied" error when running Docker commands without sudo
. This issue typically occurs because the user does not have the correct permissions to access the Docker daemon. Even after adding the user to the docker
group, the changes may not take effect immediately, leading to frustration when trying to run docker images
or other commands.
1. Remove Old Docker Versions (If Any):
sudo apt remove -y docker docker-engine docker.io containerd runc
2. Update Package Lists:
sudo apt update
3. Add Docker's Official GPG Key:
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
4. Verify Your Ubuntu Version:
lsb_release -cs
This should return noble
(for Ubuntu 24.04). If not, check your installation.
4. Set Up Docker's Stable Repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu noble stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5. Update Package Index Again:
sudo apt update
6. Install Docker Engine and Related Components:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
7. Verify Docker Installation:
sudo systemctl status docker
When the Service is working, the terminal should show:
docker.service - Docker Application Container Engine
and further information
End the running Service with:
q
8. Test Docker with a Sample Container:
sudo docker run hello-world
These steps install Docker on your machine.
When I installed Docker on my machine, there was still a message when trying to access all docker images (docker images
) on my machine:
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied
this message appears when you want to access docker images without sudo
permission on your machine.
Solution: Add Your User to the docker Group
1. Check if the docker
group exists:
getent group docker
If nothing is returned, create the group manually:
sudo groupadd docker
2. Add Your User to the docker
Group:
sudo usermod -aG docker $USER
3. Apply the Changes: Log out and log back in, or restart your machine:
newgrp docker
4. Test Running Docker without sudo
:
docker images
When you want to access the docker
system without any sudo
commands, restart your machine and it is done.
Conclusion
The "permission denied" error is usually resolved by ensuring the user is correctly added to the docker
group and restarting the system to apply the changes. If the issue persists, checking and adjusting the permissions of the Docker socket can help. After completing these steps, you should be able to run Docker commands without sudo
and manage containers smoothly.
Top comments (0)