なぜDockerコマンドにはsudoが必要なのか?
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.
To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
とのことで、docker
という名のグループを作ってユーザをそこに所属させればOKです。
やり方
# dockerグループがなければ作る
sudo groupadd docker
# 現行ユーザをdockerグループに所属させる
sudo gpasswd -a $USER docker
# dockerデーモンを再起動する (CentOS7の場合)
sudo systemctl restart docker
# exitして再ログインすると反映される。
exit
コメント
@zzerorrリンクをコピー このコメントを報告 0
@tesstesstexリンクをコピー このコメントを報告 1
すごく助かりました。ありがとうございます!
勉強になりました。
現在はドキュメントが変更されているようで、Post-installation steps for Linuxに同様の記述がありました。
またexperimentalではあるそうですがRootless modeなるものもあるそうです。