Are you irritated by the following permission denied error in Docker?
Then, most probably, you are running your Docker commands as a non-super user or without a sudo as a prefix.
To resolve this, you can simply switch to the root account and run your desired Docker command.
If you have no regular access to the root account, you can add your existing account to the Docker group, and then you can easily run your Docker commands without the root access and sudo prefix.
Step 1: Create the Docker Group
To do so, execute the following command to check if the Docker group exists in your system:
- cat /etc/group | grep docker
If the output returned a list with a Docker name, skip to the next step. Otherwise, execute the following groupadd command to create a new Docker group on your system using the sudo privilege.
- sudo groupadd docker
Step 2: Add the Current User to the Docker Group
To add the current logged-in user to the Docker group, simply execute the following command:
- sudo usermod -aG docker $USER
If you want to add someone else to the Docker group, then replace the $USER
value with the desired username.
Step 3: Refresh the Change in Docker Group
Once the user is added to the Docker group, execute the following newgrp command to instantly refresh the changes made to the Docker group:
- newgrp docker
Step 4: Verify by Running a Docker Command
Lastly, test that your desired Docker command is running without being a superuser or using the sudo prefix.
- docker run hello-world
If the above command again throws the permission denied error, then try to restart the Docker service and try again.
- sudo systemctl restart docker