/** * @return Image */ public function getImage() { if (!$this->image instanceof Image) { $this->image = new Image(); $this->image->setRepoTag($this->config['Image']); } return $this->image; }
/** * Get history of an image * * @param Image $image * * @throws \Docker\Exception\UnexpectedStatusCodeException * * @return array */ public function history(Image $image) { $response = $this->client->get(['/images/{name}/history', ['name' => $image->__toString()]]); if ($response->getStatusCode() !== "200") { throw UnexpectedStatusCodeException::fromResponse($response); } return $response->json(); }
/** * 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; }
/** * Create a job from a docker image * * @param Image $image * @param string $strategy * @param string $project * * @return \Joli\JoliCi\Job */ protected function getJobFromImage(Image $image, $strategy, $project) { list($uniq, $timestamp) = explode('-', $image->getTag()); return new Job($project, $strategy, $uniq, array('image' => $image), "", \DateTime::createFromFormat('U', $timestamp)); }
/** * Delete an image from docker daemon * * @param Image $image Image to delete * @param boolean $force Force deletion of image (default false) * @param boolean $noprune Do not delete parent images (default false) * * @throws \Docker\Exception\UnexpectedStatusCodeException * * @return ImageManager */ public function delete(Image $image, $force = false, $noprune = false) { $response = $this->client->delete(['/images/{image}?force={force}&noprune={noprune}', ['image' => $image->__toString(), 'force' => $force, 'noprune' => $noprune, 'wait' => true]]); if ($response->getStatusCode() !== "200") { throw UnexpectedStatusCodeException::fromResponse($response); } return $this; }