terminate.jpg

首页

技术分享

docker 命令免sudo执行

List plus running compose.png

在linux之上,Docker安装完成之后,默认是用docker用户来执行Docker命令的,但是我们登陆的用户通常都是自己的账户,那么就需要用sudo来执行docker命令,那么如何才能免sudo执行docker命令呢?

一下几种方法都能达到目的

最推荐的方法:

sudo usermod -aG docker $USER

其他方法

# try running
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "/home/$USER/.docker" -R
# $USER is the username of the currently logged in user.

#• Add the docker group if it doesn't already exist:
sudo groupadd docker
#• Add the connected user "$USER" to the docker group. Change the user name to match your preferred user if you do not want to use your current user:
sudo gpasswd -a $USER docker
#• Either do a newgrp docker or log out/in to activate the changes to groups.
#• You can use
docker run hello-world

#to check if you can run docker without sudo.

这些方法其实目的都是把当前用户加入到docker用户组以获得docker的使用权。

Comments:

captcha