大家也许会有这样的体验,安装好docker后,只要非root用户去使用docker相关的命令,都得在之前添加个sudo,长期用的话,显得特别繁琐,经常需要去输入密码。那么,我们该如何免去sudo docker 这种使用方式呢?很简单,三步就可以搞定。
步骤一:Create the docker
group if not exist.
sudo groupadd docker
步骤二:将当前用户添加到docker用户组中
sudo usermod -aG docker $USER
步骤三:如果前两步就搞定了的话,这一步可以不用操作了。不然,我们可以有两个选择:
方式1)退出终端,重新登录,这样直接使用docker命令一般都没问题了。
方式2)不必退出终端,执行下边命令命令,用于登录另一个群组
newgrp - docker
通过man newgrp ,得到的该命令现相关的描述信息,可以看的一目了然。 The newgrp command is used to change the current group ID during a login session. If the optional - flag is given, the user's environment will be reinitialized as though the user had logged in, otherwise the current environment, including current working directory, remains unchanged.