/var/run/docker.sock: permission denied while running docker within Python CGI script


/var/run/docker.sock: permission denied while running docker within Python CGI script



I am trying to run Python CGI script inside which I need to run docker image.
I am using Docker version 1.6.2. user is "www-data", which is added in docker group.


www-data : www-data sudo docker



On machine, with www-data I am able to execute docker commands


www-data@mytest:~/html/new$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES



I am getting following error while running docker image from Python CGI script:


fatal msg="Get http:///var/run/docker.sock/v1.18/images/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?"



Is there anything I am missing here?




1 Answer
1



Permission denied on a default install indicates you are trying to access the socket from a user other than root or that is not in the docker group. You should be able to run:


sudo usermod -a -G docker $username



on your desired $username to add them to the group. You'll need to logout and back in for this to take effect (use newgrp docker in an existing shell, or restart the daemon if this is an external service accessing docker like your cgi scripts).


newgrp docker



Note that doing this effectively gives that user full root access on your host, so do this with care.





Thanks! That helped in resolving the issue.
– user5154816
Nov 30 '16 at 0:31





Restarting your machine might also help to take effect the changes.
– learner
Apr 18 '17 at 7:10





I had to run sudo chgrp docker /var/run/docker.sock, too.
– Milanka
Apr 27 at 6:19



sudo chgrp docker /var/run/docker.sock





@Milanka if that happens on an install from the docker repos, there's something broken.
– BMitch
Apr 27 at 9:44





@BenyaminJafari did you log out and back in? The comment on restarting the service was about other daemons connecting to docker, I've removed it to avoid confusion.
– BMitch
Jul 3 at 9:44







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages