Riyadh Kenaya
Riyadh Kenaya

Reputation: 11

Docker Python issue

I am creating a python script to run a docker image. I am using the command:

client.containers.run("-p 9000:9000 -p 8000:8000 -t -i bamos/openface /bin/bash", "echo hello world")

Python returns an error message:

ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))

this is an understood error since the command requires a sudo prefix then it prompts a password.

My question here is how to run sudo-based commands in python and how to insert the required password within the code.

Upvotes: 0

Views: 259

Answers (2)

Shabaz Patel
Shabaz Patel

Reputation: 291

You need to add user to the docker group as follows,

 usermod -aG docker $SUDO_USER

 Ex:
 usermodel -aG docker ubuntu

Please do exit and ssh back in after adding the user

Upvotes: 0

Vlad
Vlad

Reputation: 9481

You actually don't need a sudo for this command. Most likely reason you are getting this error is because you don't have access to the docker socket. All you need to do is to add yourself to the docker group. Make sure you log out and log back in after you do that.

Running things as root via sudo or some other means is bad security practice.

Upvotes: 1

Related Questions