Reputation: 83
I am running a php script which runs a exec() function to run a docker container.
i echo my user via php
exec("whoami 2>&1",$out);
var_dump($out);
it shows deamon. The code i am trieng to run is:
exec("docker run --rm -d -i -t -v ".$targetPath.":/user threed sh /user/test.sh 2>&1",$out);
var_dump($out);
but the error i got is
string(237) "docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/create: dial unix /var/run/docker.sock: connect: permission denied." [2]=> string(24) "See 'docker run --help'. "
can any one help me out to run docker container from my php script.
Upvotes: 0
Views: 1680
Reputation: 1173
The problem is related to the user running your PHP code. First you need to determinate which user is running the PHP code. Is it your user?, is it php-fpm? www-data? After that you need to add that user to the docker user group. More info on this in the following link: https://docs.docker.com/install/linux/linux-postinstall/
Upvotes: 3