I'm trying run command from my index.php:
$output = shell_exec('docker images');
and then output results,
or run new container the same way:
$output = shell_exec('docker run hello-world');
It seems that I could not run ANY docker cmd via php.
How do it properly?
I did the following to get this working:
Created a php file called index.php on /var/www/html/ with this content:
<?php
echo '<pre>';
$content = system('sudo docker images', $ret);
echo '</pre>';
?>
Edited sudoers file with visudo, adding the following line at the end:
www-data ALL=NOPASSWD: /usr/bin/docker
Checked http://localhost/index.php
and it worked!
You can even build and run containers with this, hope it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With