How to Add User to Docker Group?

Docker is an open-source software library to develop, manage and run applications efficiently. Docker acts as a container for automating the deployment of Linux applications. It was built on top of Linux Containers (LXC) initially, but later on, the docker replaced the Linux container. The user can run any package container. Sometimes, you need to give several users common permissions in docker, which can be done by adding them to a group. This guide will discuss the below-written topics:

Let’s start with creating the docker group.

How to Create a Docker Group?

Do you want to set certain permissions for all the users? You can create a group and all the users to that group. You can create and verify the docker group by following these easy steps:

Step 1: Create a Docker Group

To create a docker group, the “groupadd” command is shown below:

$ sudo groupadd docker

The “docker” group was successfully created.

Step 2: Restart the Docker

Restart the docker to load the group changes, using this command:

$ sudo systemctl restart docker

The docker has restarted, and now we can verify the group creation.

Step 3: Verify the Docker Group

To check that the docker group is successfully created in the system, execute this command:

$ grep docker /etc/group

The output shows the “docker” group is successfully created with the GroupID (GID) 1004.

Let’s add a new user to the docker group.

How to Add Users to Docker Group?

The “usermod” adds a user to the docker group. Its general syntax is below:

$ sudo usermod -aG docker user-name

The command’s components are as follows:

  • a: This option enables appending new users to supplementary groups.
  • G: This option indicates the supplementary group.
  • user-name: Replace it with the specific user.

Add Any User to Docker Group

For instance, to add a user named “milton” to a docker group, execute this command:

$ sudo usermod -aG docker milton

The user “milton” is now added to the docker group.

To verify the user “milton” is added to the “docker” group, the following command is used:

Note:milton” is another user in the system.

$ groups milton

 The output shows “milton” is a member of the “docker” group.

Add Currently Logged-in User to Docker Group

To add the currently logged-in user to the docker group, use the following command:

$ sudo usermod -aG docker $USER

The logged-in user is successfully added to the “docker” group.

To verify the currently logged-in user is a member of the “docker” group, utilize this command:

$ groups $USER

The output indicates that the current user is a member of the “docker” group.

That’s the end of this guide.

Conclusion

Docker is an open-source application managing platform where users can be added to the docker group using the “sudo usermod -aG docker user-name” command. Moreover, this article has discussed creating a docker group and adding a specific user or current user.