如何在 php 脚本的容器内启动函数?执行还是系统?
How to launch a function inside a container for a php script ? Exec or system?
这是我的问题:我有一个 docker 容器,其中包含一个函数。我需要在终端上写这个命令才能启动我的功能:
docker run -p 80:8080 -it custom_docker bin/bash
/home/prog/executable_script -command 'string'
我想将此函数放在 php 脚本中的 textarea
中,但我应该如何正确编写它才能使其出现在我的 localhost
中?
我试过了,但没用:
<html>
<body>
<textarea id="strings" name="chain" style="border: solid 1px #99bb99; width: 100%; margin: 0px; padding: 2px;" rows="25" cols="45">
<?php
echo '<pre>';
$content = system("sudo docker run -it custom_docker /bin/bash -w /home/prog/executable_script -command 'string');
echo '</pre>';
?>
</textarea>
</body>
</html>
只有<pre></pre>
被写为输出...
感谢您的帮助!
也很抱歉我的英语不好
您永远不会回显您的 $content
变量,因此它总是将 <pre></pre>
写入内容。
要发送命令的输出:
echo system("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");
或
passthru("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");
至 ensure that your script runs correctly with sudo privileges,编辑 sudoers 文件并添加规则以允许 Web 服务器调用您的脚本:
www-data ALL=NOPASSWD: /path/to/your/docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'
这是我的问题:我有一个 docker 容器,其中包含一个函数。我需要在终端上写这个命令才能启动我的功能:
docker run -p 80:8080 -it custom_docker bin/bash
/home/prog/executable_script -command 'string'
我想将此函数放在 php 脚本中的 textarea
中,但我应该如何正确编写它才能使其出现在我的 localhost
中?
我试过了,但没用:
<html>
<body>
<textarea id="strings" name="chain" style="border: solid 1px #99bb99; width: 100%; margin: 0px; padding: 2px;" rows="25" cols="45">
<?php
echo '<pre>';
$content = system("sudo docker run -it custom_docker /bin/bash -w /home/prog/executable_script -command 'string');
echo '</pre>';
?>
</textarea>
</body>
</html>
只有<pre></pre>
被写为输出...
感谢您的帮助!
也很抱歉我的英语不好
您永远不会回显您的 $content
变量,因此它总是将 <pre></pre>
写入内容。
要发送命令的输出:
echo system("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");
或
passthru("sudo docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'");
至 ensure that your script runs correctly with sudo privileges,编辑 sudoers 文件并添加规则以允许 Web 服务器调用您的脚本:
www-data ALL=NOPASSWD: /path/to/your/docker run custom_docker /bin/bash /home/prog/executable_script -command 'string'