Run Docker as non root user without sudo command
By default docker command need root permission because The docker daemon runs as the root user. So by default, either you need to be the root user or you have to run docker with the sudo command.
But, How do we run docker as non root without sudo command?
In Order to run run docker without sudo, the user must be a member of the docker admin group. First of all check whether docker group is already in your Linux system.
grep docker /etc/group
If not, Do the following steps to create docker group and run docker without sudo.
-
First, Create the docker group:
sudo groupadd docker
-
Then, Restart the docker service. (This is important):
systemctl restart docker
-
Now, you can add the non root user to the docker group, (Replace the "username" with actual username):
gpasswd -a username docker
Make sure that the user is in the docker admin group:
grep docker /etc/group
Now re login to the non root user account and try to run docker command without sudo.
docker images
If user is in the docker group, the user should be able to run docker without sudo.