我有这个PHP脚本(用于Docker远程API),我用它来停止容器"远程":
<?php
$cid = trim(file_get_contents('cid'));
echo "$cid\n";
function httpPost($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST, true);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$url = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
echo "$url\n";
echo httpPost($url)
?>
有效!但是我想把这段代码放到&#34;停止&#34; 两个 docker容器,而不只是一个。
我在考虑这样的事情:
$cid = trim(file_get_contents('cid'));
$pid = trim(file_get_contents('pid'));
然后代码的其余部分将如何显示,以便我们停止它们?
答案 0 :(得分:0)
切换这部分:
$url = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
echo "$url\n";
echo httpPost($url)
到此
$url1 = "http://172.17.0.1:2375/containers/$cid/stop?t=5";
$url2 = "http://172.17.0.1:2375/containers/$pid/stop?t=5";
echo httpPost($url1);
echo httpPost($url2);
你怎么做基本。可以创建更复杂的结构。