How can I run the sudo command in Python code under CentOS in Docker
0
votes
1
answer
2309
views
I am trying to access the docker image labels from Python as follows
hostname = socket.gethostname()
cmd = "sudo curl --unix-socket /var/run/docker.sock http:/containers/" + hostname + "/json"
output = os.popen(cmd).read()
But, the thing is I am getting the following error:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
It's one of the fancy messages by Unix from some other posts I read from StackOverflow.
I am following the below link
https://stackoverflow.com/questions/37439887/how-to-access-the-metadata-of-a-docker-container-from-a-script-running-inside-th
Only thing is I want to run these things from Python not from the Terminal.
Also, FYI, I get the response when I run the same command from the terminal.
I tried appending the following piece in Dockerfile
RUN echo "root ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
Thanks
Asked by jaruto
(1 rep)
Jan 29, 2019, 07:29 PM
Last activity: Jul 20, 2025, 11:07 PM
Last activity: Jul 20, 2025, 11:07 PM