rkey

rkey

How to allow ordinary users to execute and manage Docker

To allow regular users to execute and manage Docker without needing to use sudo, you can add the user to the docker group. Here are the specific steps:

1. Create the docker group (if it doesn't already exist)#

First, ensure that the docker group exists. If it does not, you can create it using the following command:

sudo groupadd docker

2. Add the user to the docker group#

Add the regular user to the docker group. Assuming the username of the regular user is rkey, you can use the following command:

sudo usermod -aG docker rkey
  • -aG: -a means append, -G means group.
  • docker: group name.
  • rkey: username.

3. Log out or restart the system#

To make the group membership changes effective, the user needs to log out or restart the system. You can choose either of the following methods:

  • Log out: Sign out and sign back in.
  • Restart the system: Use the following command to restart the system:
    sudo reboot
    

4. Verify if the user has been added to the docker group#

After logging back in or restarting the system, verify if the user has been successfully added to the docker group:

groups rkey

You should see the docker group in the output.

5. Test Docker commands#

Try running a Docker command, for example:

docker version

If the command executes successfully without prompting for sudo, it means the user can now run Docker commands without sudo.

Notes#

  • Security: Adding a user to the docker group means that the user will have permissions similar to that of the root user, as the Docker daemon runs with root privileges. Ensure you trust this user, as it may pose security risks.
  • Multi-user environment: In a multi-user environment, ensure that all users who need to use Docker are added to the docker group.

By following these steps, you can allow regular users to execute and manage Docker without sudo.

The following error applies to this method:

docker ps permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json": dial unix /var/run/docker.sock: connect: permission denied

The mentioned link http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json is a URL-encoded path, and the actual path is http:///var/run/docker.sock/v1.47/containers/json. This path is the Unix socket path for the Docker daemon, used for communication with the Docker daemon.

  • Link resolution issue: This link is not a regular HTTP URL, but a Unix socket path. Therefore, you cannot access it directly in a browser like a regular web page. This path is used for communication between the Docker client and the Docker daemon.
  • Network issues: If you encounter issues when trying to access this path, it is usually due to permission issues or the Docker service not running. Ensure you have added the user to the docker group as described above and that the Docker service is running.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.