sudo usermod -aG docker $USER
Running the command
sudo usermod -aG docker $USER adds your user
to the "docker" group, allowing you to use Docker commands without using sudo
each time. However, please note that changes to group membership do not take
effect in the current shell session. After running the command, you would
generally need to either log out and log back in or run the
newgrp docker command to start a new shell session with the
updated group membership.
Here's a breakdown of what each command does:
- sudo usermod -aG docker $USER: This command adds your current user ($USER) to the "docker" group using the usermod command. The -aG options stand for "append to group" and specify that you want to add the user to the specified group.
- newgrp docker: This command starts a new shell session with the group set to "docker". This allows you to immediately start using Docker commands without needing to log out and log back in.
By running these commands, you'll be able to use Docker commands comfortably without needing to prepend sudo every time. Just make sure to open a new terminal or shell session after making these changes for the group membership to take effect.