Creating non-root user with Docker permissions
Creating non-root user with docker permissiosn:
Adding a user with sudo permissions
First we need to create a user
useradd -G sudo -m placeholder-username -s /bin/bash
Breakdown of command:
useradd
is the command for creating a new user-G
is tag for group, you are creating user to be put in the sudo group-m
is for the username-s
indicates the default shell, in this case it is /bin/bash
Next, you need to create a password for your user:
passwd placeholder-username
Enter your password, and reenter your password to confirm. This is now your sudo
password. REMEMBER IT!
And That’s it! You’ve successfully created a non-root user!
To find the UID
(User ID) and GID
(Group ID) of that user, enter:
id placeholder-username
The output will display a number. Note down that number.
Adding docker permissions to the non-root user
Ensure docker group is created:
sudo groupadd docker
Change user to newly created user:
su placeholder-username
You will be prompted to enter your password. Enter it and continue:
Adding your non-root user to the docker
group:
sudo usermod -aG docker $USER
To apply changes enter:
newgrp docker
Verify you can run docker
commands without sudo
:
docker run hello-world
If you see an output like the one shown below, then you have set everything up correctly!