解決使用docker命令總是要輸入sudo的問題

      大家也許會有這樣的體驗,安裝好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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章