Open In App

How To Add User To Docker Group?

Last Updated : 11 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Adding the user to the docker group is a common practice adding the user to the docker group allows you to interact with the docker daemon without requiring sudo pervillages. Without adding a user to the Docker group, running Docker commands typically requires superuser privileges. Adding a user to the docker group allows you to run the commands without docker privileges.

What Is Docker Group

Docker Group is a user group in the Linux system. The Docker group is associated with the Docker daemon when the docker is installed in the Linux system to interact with the docker daemon for a particular user it requires sudo privileges if you add the particular user from which you want to run the commands to the docker group then there will be no need of sudo you can directly run the commands in the docker.

How To Get Docker Group ID

To the docker group ID, you can use the below command

getent group docker

docker group id

Steps To Add User To Docker Group

First, install the docker in that Linux server where you want to containerize your application.

Step 1: After installing the docker use the command to add the user to the docker group is as follows.

sudo usermod -aG docker username

-aG docker: These are options for the usermod command:

  • -a: This option appends the user to the supplementary group(s) specified without removing the user from other groups.
  • -G docker: This specifies the group to which the user is being added, in this case, the “docker” group.

In my case the user was ubuntu so i am using the following command.

sudo usermod -aG docker ubuntu

usermod

You can see in the above image we are adding the ubuntu user to the docker group and after we are pulling the smaple docker image from the public docker hub registry with out using the “sudo privillages.”

If you are able to pull the image sucessfully then you have added the ubunutu user to the docker group know you can execute the commands with out “sudo”

What Is The Docker User Home Directory?

The Docker user home directory, often referred to as the home directory of the Docker daemon or Docker service account, depends on the Linux distribution and how Docker is installed.

In many cases, the Docker daemon runs as a system service and doesn’t have a traditional home directory associated with a specific user account. Instead, Docker daemon processes typically run with system-level privileges.

However, if you are referring to the home directory of a user who interacts with Docker (such as a user added to the “docker” group to run Docker commands without sudo), the home directory would be the home directory of that specific user.

You can determine the home directory of the currently logged-in user by using the echo command with the HOME environment variable. For example:

echo $HOME

Docker Group – FAQ’s

How do I create a user for docker container?

You can use the below commad inside the dockerfile to create a user for docker container.

RUN groupadd -r groupname && useradd -r -g groupname username
  • groupadd is used to create a group (groupname).
  • useradd is used to create a user (username) and add them to the specified group.
  • The USER instruction sets the default user for the subsequent commands in the Dockerfile.

How do I see users in docker?

Use the following command to inspect the detailed configuration of a running or stopped container:

docker inspect <container_name_or_id>

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads