Bootstrap FreeKB - Python (Scripting) - Resolve "Permission Denied" with Python DockerClient
Python (Scripting) - Resolve "Permission Denied" with Python DockerClient

Updated:   |  Python (Scripting) articles

Let's say you are using the Python DockerClient.

#!/usr/bin/python3
import docker
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')

 

And something like this is being returned. Let's say this is happening when running the Python DockerClient script as user john.doe on a Linux system.

[john.doe@server1 ~]# python3 example.py
Error while fetching server API version: ('Connection aborted.', PermissionError(13, 'Permission denied'))

 

If you are on a Linux system, the docker group should not contain any users, which can be seen by the fact that there are no users in field 4 in the following.

~]$ cat /etc/group | grep -i docker
docker:x:992:

 

And the groups command can be used to see if your user is a member of the docker group.

~]$ groups
john.doe

 

The usermod command can be used to add your user to the docker group.

usermod -aG docker john.doe

 

Disconnect your SSH session to the Docker system, reconnect, and verify you are now a member of the docker group.

[john.doe@server1 ~]$ groups
john.doe docker

 

Likewise, the /etc/group file should show that your user is now a member of the docker group.

~]$ cat /etc/group | grep -i docker
docker:x:992:john.doe

 

And try again.

[john.doe@server1 ~]# python3 example.py
all good!

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 0804e7 in the box below so that we can be sure you are a human.