This write-up will demonstrate the method to use Docker without sudo.
How to Utilize Docker Without sudo?
To use Docker with sudo, try out the below-mentioned steps:
- Make a Docker group.
- Add a new user to the Docker group.
- Verify by running Docker commands without sudo.
Step 1: Create/Make a Docker Group
First, make a Docker group by executing the below-listed command in the Ubuntu terminal:
The above output shows that there is already a Docker group.
Step 2: Add New User
Then, utilize the given-provided command to add the new user to the Docker group:
Here:
- The “usermod” command modifies an account of user on the system.
- The “-aG docker” option adds the new user to the Docker group. The “-a” flag determines that the user should be added to the group, the “-G” flag specifies the group to which user should be added.
- The “docker” is the group name.
- “$USER” is a variable for the current user’s username:
In this way, the above command has been successfully executed.
Step 3: Verification
Finally, write out the following Docker command in the terminal without using the “sudo” command for the verification:
As users can see, we have successfully used the Docker command without the sudo command.
Conclusion
To use Docker without sudo, first, make a Docker group if it does not already occur. Next, add the new user to the Docker group via the “sudo usermod -aG docker $USER” command. Lastly, verify the changes by executing the Docker command without the sudo command. This write-up has demonstrated the method to use Docker without sudo.