If you want to avoid typing sudo
whenever you run the docker
command, add your username to the docker
group:
sudo usermod -aG docker ${USER}
To apply the new group membership, you can log out of the server and back in, or you can type the following:
su - ${USER}
You will be prompted to enter your user's password to continue. Afterwards, you can confirm that your user is now added to the docker
group by typing:
id -nG
style="display:block; text-align:center;"
data-ad-format="fluid"
data-ad-layout="in-article"
data-ad-client="ca-pub-3089600610336467"
data-ad-slot="5786342409">
Output
sammy sudo docker
If you need to add a user to the docker
group that you're not logged in as, declare that username explicitly using:
sudo usermod -aG docker username
The rest of this article assumes you are running the docker
command as a user in the docker user group. If you choose not to, please prepend the commands with sudo