Docker起動時にGet Permission Denied while trying to connect解決方法を提示する

1666 ワード

環境の説明
vmware 15仮想マシンインストールcentos 7.4 64ビットシステム、dockerバージョン19.03.2
問題の説明
dockerのインストールが完了したら、docker関連コマンドを実行します
docker run ubuntu:15.10 /bin/echo "Hello world"

次のプロンプトが表示されます.
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker....: dial unix/var/run/docker.sock: connect: permission denied.
理由はdocker mannualの言葉から
Manage Docker as a non-root user
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 only access it using sudo. The docker daemon always runs as the root user.
If you don’t want 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プロセスはTCPポートではなくUnix Socketを使用します.デフォルトでは、Unix socketはrootユーザーに属し、root権限が必要です.
解決方法1
sudoを使用して管理者権限を取得しdockerコマンドを実行する
#          
sudo docker run ubuntu:15.10 /bin/echo "Hello world"

解決策2
dockerデーモンが起動すると、デフォルトではdockerという名前のユーザーグループにUnix socketを読み書きする権限が与えられます.そのため、dockerユーザーグループを作成し、現在のユーザーをdockerユーザーグループに加入すれば、現在のユーザーはUnix socketにアクセスする権限があり、docker関連コマンドを実行することができます.
sudo groupadd docker     #  docker   
sudo gpasswd -a $USER docker     #        docker    
newgrp docker     #     
docker ps    #  docker        sudo    

この文書は次のとおりです.https://www.fengjunzi.com/blog-25467.html
私のウェブサイトへようこそ:風君子ブログ、マイクロ信号fj 3702交流