【问题标题】:Unable to execute a bash script containing docker commands from a php file无法从 php 文件执行包含 docker 命令的 bash 脚本
【发布时间】:2018-10-27 07:11:25
【问题描述】:

我正在运行以下 php 脚本。它创建了一个运行几个 docker 命令的脚本文件。但是这个脚本文件由于某种原因没有运行 docker 命令。它运行正常的脚本文件命令,如 ls、pwd、echoetc。

$code = $_POST['source']; 
$myfile = fopen("abc.py", "w");
fwrite($myfile, $code);
$myfile_new = fopen("execu_ta.sh", "w");
$txt = "#!/bin/bash\n\n";
fwrite($myfile_new, $txt);
$txt1 = "docker build -t python-new-world .";  
$txt2 = "docker run python-new-world\n";
fwrite($myfile_new, $txt1);
fwrite($myfile_new, $txt2);
$result=shell_exec('path of the "execu_ta.sh" file');
echo $result;

?>

这里可能有什么问题?

【问题讨论】:

  • 需要设置可执行位或者使用shell_exec('/bin/bash your_script')
  • @Ujin,也许您可​​以添加您的评论作为答案,这样您就可以获得荣誉?

标签: php shell docker


【解决方案1】:

您需要设置可执行位chmod("your script filename", 0755);或使用shell_exec('/bin/bash your_script')

【讨论】:

  • 那它为什么运行shell命令呢?可能是脚本存在并具有必要的权限?
【解决方案2】:

除了 Ujin 的回答,我也会刷新并关闭文件,否则您可能最终会执行一个空脚本。确保 docker 在你的 PATH 上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-18
    • 2020-06-24
    • 2021-12-31
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    相关资源
    最近更新 更多