Ejemplo n.º 1
0
 /**
  * Commit a container into an image
  *
  * @param \Docker\Container $container
  * @param array             $config
  *
  * @throws Exception\UnexpectedStatusCodeException
  *
  * @return \Docker\Image
  *
  * @see http://docs.docker.com/reference/api/docker_remote_api_v1.7/#create-a-new-image-from-a-containers-changes
  */
 public function commit(Container $container, $config = [])
 {
     if (isset($config['run'])) {
         $config['run'] = json_encode($config['run']);
     }
     $config['container'] = $container->getId();
     $response = $this->httpClient->post(['/commit{?config*}', ['config' => $config]]);
     if ($response->getStatusCode() !== "201") {
         throw new UnexpectedStatusCodeException($response->getStatusCode(), (string) $response->getBody());
     }
     $image = new Image();
     $image->setId($response->json()['Id']);
     if (array_key_exists('repo', $config)) {
         $image->setRepository($config['repo']);
     }
     if (array_key_exists('tag', $config)) {
         $image->setTag($config['tag']);
     }
     return $image;
 }
Ejemplo n.º 2
0
 /**
  * Remove multiple images from docker daemon
  *
  * @param Image[]|array $images  Images to remove
  * @param boolean       $force   Force removal of image (default false)
  * @param boolean       $noprune Do not remove parent images (default false)
  *
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  *
  * @return ImageManager
  */
 public function removeImages(array $images, $force = false, $noprune = false)
 {
     foreach ($images as $image) {
         if (!$image instanceof Image) {
             $imageId = $image;
             $image = new Image();
             $image->setId($imageId);
         }
         $this->remove($image, $force, $noprune);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Inspect a image
  *
  * @param \Docker\Image $image
  *
  * @throws \Docker\Exception\ImageNotFoundException
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  * @throws \GuzzleHttp\Exception\RequestException
  *
  * @return ImageManager
  */
 public function inspect(Image $image)
 {
     try {
         $response = $this->client->get(['/images/{id}/json', ['id' => $image->__toString()]]);
     } catch (RequestException $e) {
         if ($e->hasResponse() && $e->getResponse()->getStatusCode() == "404") {
             throw new ImageNotFoundException($image->__toString(), $e);
         }
         throw $e;
     }
     if ($response->getStatusCode() !== "200") {
         throw UnexpectedStatusCodeException::fromResponse($response);
     }
     $data = $response->json();
     $image->setId($data['Id']);
     // @TODO Add extra info on image
     return $this;
 }