docker add user to docker group code example

Example 1: make docker sudo less

$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ newgrp docker

Example 2: add user to docker group

sudo usermod -aG docker $USER   #$USER is your username

Example 3: docker post installation steps linux

# Creates docker group
sudo groupadd docker

# Add your user to the docker group
sudo usermod -aG docker $USER

# Log out and log back in so that your group membership is re-evaluated
# GNOME example
gnome-session-quit

Example 4: write command docker without need write sudo

#for write command docker without need write sudo  #add all command in your terminal
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

Example 5: add user to docker group

sudo gpasswd -a $USER docker

Example 6: docker alpine create user and group

# To create a non root group and user inside your Alpine based Dockerfile

# -g is the GID
addgroup -g 1000 groupname

# -u is the UID
# -D permits to create an user without password
adduser -u 1000 -G groupname -h /home/username -D username