我正在尝试从我的index.php运行命令:
$output = shell_exec('docker images');
然后输出结果,
或以相同的方式运行新容器:
$output = shell_exec('docker run hello-world');
似乎我无法通过php运行任何docker cmd。
怎么做得好?
答案 0 :(得分:3)
我做了以下工作来实现这个目标:
答案 1 :(得分:2)
你可以这样做:
vi rd.php
将此内容放在rd.php文件中
<?php
$output = shell_exec('RET=`docker run hello-world`;echo $RET');
echo $output;
现在你可以运行
了php rd.php
您可以查看结果:
Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash For more examples and ideas, visit: http://docs.docker.com/userguide/
这就是全部!
我希望这可以帮到你