After installing docker, there will usually be a docker user groupStep 2: Add the current user to the docker group sudo gpasswd -a ${USER} docker Step 3: Restart Docker sudo systemctl restart docker Step 4: Grant read and write permissions sudo chmod a+rw /var/run/docker.sock Supplement: Non-root users do not have permission to use docker No permission is prompted when running docker runOfficial documentation for installing Docker on CentOS The docker user group is automatically created when installing docker-ce, but you need to manually add users to the docker user group $ sudo usermod -aG docker $USER Or $ sudo usermod -aG docker {specify username} But after adding the user to the docker user group, it still prompts no permission For example, I want to run bash on Ubuntu 14.04: [hsowan@localhost shell-workspace]$ docker run -it --rm ubuntu:14.04 bash docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/create: dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'. Why? The reason is that although the user has joined the docker user group, he has not switched to the docker user group, so he still has no permissions. If a user belongs to multiple user groups at the same time, the user can switch between user groups to have the permissions of other user groups. $ newgrp docker Now you can execute docker related commands under non-root users In addition to adding user groups to users, is there any other way to allow non-root users to execute docker-related commands? OK, let's check the permissions of /var/run/docker.sock $ sudo ll /var/run/docker.sock You will get the following result: srw-rw----. 1 root docker 0 Sep 22 15:29 /var/run/docker.sock So now directly modify the permissions of /var/run/docker.sock $ sudo chmod 666 /var/run/docker.sock Now you can run docker as a non-root user $ docker run -it --rm ubuntu:14.04 bash root@5c60abab6425:/# cat /etc/os-release NAME="Ubuntu" VERSION="14.04.5 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.5 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" root@5c60abab6425:/# exit exit The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
<<: MySQL online log library migration example
>>: Web front-end development course What are the web front-end development tools
I used to think that script could be placed anywh...
Preface In the actual use of the database, we oft...
A status code that indicates a provisional respon...
Introduction to Git Git is an open source version...
Table of contents Preface What is data binding? T...
In MySQL, you can use IF(), IFNULL(), NULLIF(), a...
Many organizations have the need to back up file ...
1. Introduction Our real servers should not be di...
Before starting the main text of this article, yo...
@Font-face basic introduction: @font-face is a CSS...
Preface At work, we often need to operate in a Li...
Programs in Docker containers often need to acces...
On mobile devices, flex layout is very useful. It...
Table of contents Write docker-compose.yml Run do...
This article example shares the specific code of ...