How to Add the Current User to a Docker Group: Quick Guide

Are you struggling to run Docker containers without root privileges? To do so, it’s important for you to learn how to add your user to a Docker group on Linux.

Let’s start the process!

How to Add the Current User to a Docker Group?

For adding the current user to the Docker group on Linux:

Step 1: Check for Existing Docker Group (Optional)

Firstly, verify the docker group already exists on the Ubuntu 24.04 system:

cat /etc/group | grep docker

Or run:

grep docker /etc/group
check for existing docker group on linux

Note: The group already exists if the command outputs a line with docker. Skip to step 2.

Step 2: Create the Docker Group (if needed)

If the group doesn’t exist, use sudo to create a docker group as below:

sudo groupadd docker
create-the-docker-group-on-linux

Step 3: Add User to Docker Group

Next, add your user to the Docker group with this usermod command:

sudo usermod -aG docker $USER

Here, the -a option tells usermod to append the group (not replace existing ones). Meanwhile, -G specifies the group to add:

add user to docker group on linux

Step 4: Refresh Group Membership (Choose One)

Now, log out and log back in for the modifications to take effect.

In contrast, run the newgrp command to switch to the docker group in the current session (it doesn’t persist after closing the terminal):

newgrp docker
refresh group membership on linux

Step 5: Verify the Changes

Finally, try running a Docker command without sudo by running a simple test:

docker run hello-world
verify the changes on linux

In this way, you can add the current user to the Docker group using the “sudo usermod -aG docker $USER” command in the Ubuntu 24.04 terminal.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top