コード例 #1
0
 /**
  * Get all containers from the docker daemon
  *
  * @param array $params an array of query parameters
  *
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  *
  * @return Container[]
  */
 public function findAll(array $params = [])
 {
     $response = $this->client->get('/containers/json', ['query' => $params]);
     if ($response->getStatusCode() !== "200") {
         throw UnexpectedStatusCodeException::fromResponse($response);
     }
     $coll = [];
     $containers = $response->json();
     if (!is_array($containers)) {
         return [];
     }
     foreach ($containers as $data) {
         $container = new Container();
         $container->setId($data['Id']);
         $container->setImage($data['Image']);
         $container->setCmd((array) $data['Command']);
         $container->setData($data);
         $coll[] = $container;
     }
     return $coll;
 }