0

Trying to run docker exec from php under Nginx I get the following error:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/konfetki_db_1/json: dial unix /var/run/docker.sock: connect: permission denied

This works from command line but it says permission denied while I'm trying to run from php under nginx with www-data instead of root.

Is there any way to run this?

Zahra
  • 2,231
  • 3
  • 21
  • 41
  • The user which runs php does not have permissions to access the ``docker`` group, follow this guide: https://stackoverflow.com/questions/48957195/how-to-fix-docker-got-permission-denied-issue but instead of using your own user, add the user where php runs. If you don't know it, ```` will do the job. – Marc Sances Aug 21 '20 at 18:16
  • If you can run any `docker` command at all, it's pretty easy to root the whole host. I'd encourage you to rearchitect your application to not directly need to run `docker` commands, and avoid `docker exec` except for occasional debugging tasks. – David Maze Aug 21 '20 at 23:40

1 Answers1

0

I solved problem by this:

Add docker group
$ sudo groupadd docker
Add your current user to docker group
$ sudo usermod -aG docker www-data
Switch session to docker group
$ newgrp - docker
Run an example to test
$ docker run hello-world