/** * Tag an image * * @param Image $image image to tag * @param $repository Repository name to use * @param string $tag Tag to use * @param bool $force Force to set tag even if an image with the same name already exists ? * * @throws \Docker\Exception\UnexpectedStatusCodeException * * @return ImageManager */ public function tag(Image $image, $repository, $tag = 'latest', $force = false) { $response = $this->client->post(['/images/{name}/tag?repo={repository}&tag={tag}&force={force}', ['name' => $image->getId(), 'repository' => $repository, 'tag' => $tag, 'force' => intval($force)]]); if ($response->getStatusCode() !== "201") { throw UnexpectedStatusCodeException::fromResponse($response); } $image->setRepository($repository); $image->setTag($tag); return $this; }
/** * 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; }