I'm trying to run docker as a non-root user. When I try, I get the following error:
$ docker ps
FATA[0000] Get http:///var/run/docker.sock/v1.18/containers/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?
I can run docker as root:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[...]
I've put this user into a Unix group docker
:
$ groups
domain users docker suappprod stashadmin config_mgmt remote server access sudevmail sudevsvn
However, it still appears that this user cannot run most of the docker commands without sudoing as root.
I am on an older version of docker:
$ docker --version
Docker version 1.6.1, build a8a31ef/1.6.1
I know that the latest is 1.10, and it's possible for our company to update all of the docker installs to 1.9.2, but that will take a lot of effort and time.
Is there something else I need to look at? The user has been logged in and out multiple times. I have not rebooted the system yet.
One of the best practices while running Docker Container is to run processes with a non-root user. This is because if a user manages to break out of the application running as root in the container, he may gain root user access on host.
To run a command as a different user inside your container, add the --user flag: docker exec --user guest container-name whoami.
Add a non-privileged user and set it as the process owner The second line sets the Dockerfile to switch to the newly created user. There's a point in setting it to the UID rather than the username, and we'll get to it. With just this change, your container will now run as a non-privileged user!
Adding users to the Docker group (since Docker group has full control to the socket)
As root, add the user to the docker group:
This is how I've been able to set it up on my Ubuntu systems time and time again.
Check what this command gives
--> ls -l /var/run/docker.sock
You may want to change the permissions of this file using chmod (Ex: sudo chmod 777 /var/run/docker.sock
) depending on what permissions you want to give.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With