@@ -278,6 +278,120 @@ public function containerCopy($container, $config)
278278 return $ this ->postJson ($ this ->url ('/containers/%s/copy ' , $ container ), $ config )->then (array ($ this ->parser , 'expectPlain ' ));
279279 }
280280
281+ /**
282+ * List images
283+ *
284+ * @param boolean $all
285+ * @return Promise Promise<array> list of image objects
286+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#list-images
287+ * @todo support $filters param
288+ */
289+ public function imageList ($ all = false )
290+ {
291+ return $ this ->browser ->get ($ this ->url ('/images/json?all=%u ' , $ all ))->then (array ($ this ->parser , 'expectJson ' ));
292+ }
293+
294+ /**
295+ * Create an image, either by pulling it from the registry or by importing it
296+ *
297+ * @param string|null $fromImage name of the image to pull
298+ * @param string|null $fromSrc source to import, - means stdin
299+ * @param string|null $repo repository
300+ * @param string|null $tag (optional) (obsolete) tag, use $repo and $fromImage in the "name:tag" instead
301+ * @param string|null $registry the registry to pull from
302+ * @param array|null $registryAuth AuthConfig object (to send as X-Registry-Auth header)
303+ * @return Promise Promise<array> stream of message objects
304+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-an-image
305+ */
306+ public function imageCreate ($ fromImage = null , $ fromSrc = null , $ repo = null , $ tag = null , $ registry = null , $ registryAuth = null )
307+ {
308+ return $ this ->browser ->post (
309+ $ this ->url ('/images/create?fromImage=%s&fromSrc=%s&repo=%s&tag=%s®istry=%s ' , $ fromImage , $ fromSrc , $ repo , $ tag , $ registry ),
310+ $ this ->authHeaders ($ registryAuth )
311+ )->then (array ($ this ->parser , 'expectJson ' ));
312+ }
313+
314+ /**
315+ * Return low-level information on the image name
316+ *
317+ * @param string $image image ID
318+ * @return Promise Promise<array> image properties
319+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#inspect-an-image
320+ */
321+ public function imageInspect ($ image )
322+ {
323+ return $ this ->browser ->get ($ this ->url ('/images/%s/json ' , $ image ))->then (array ($ this ->parser , 'expectJson ' ));
324+ }
325+
326+ /**
327+ * Return the history of the image name
328+ *
329+ * @param string $image image ID
330+ * @return Promise Promise<array> list of image history objects
331+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#get-the-history-of-an-image
332+ */
333+ public function imageHistory ($ image )
334+ {
335+ return $ this ->browser ->get ($ this ->url ('/images/%s/history ' , $ image ))->then (array ($ this ->parser , 'expectJson ' ));
336+ }
337+
338+ /**
339+ * Push the image name on the registry
340+ *
341+ * @param string $image image ID
342+ * @param string|null $tag (optional) the tag to associate with the image on the registry
343+ * @param string|null $registry (optional) the registry to push to (e.g. `registry.acme.com:5000`)
344+ * @param array|null $registryAuth (optional) AuthConfig object (to send as X-Registry-Auth header)
345+ * @return Promise Promise<array> list of image push messages
346+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#push-an-image-on-the-registry
347+ */
348+ public function imagePush ($ image , $ tag = null , $ registry = null , $ registryAuth = null )
349+ {
350+ $ path = '/images ' . ($ registry === null ? '' : ('/ ' . $ registry )) . '/%s/push?tag=%s ' ;
351+ return $ this ->browser ->post ($ this ->url ($ path , $ image , $ tag ), $ this ->authHeaders ($ registryAuth ))->then (array ($ this ->parser , 'expectJson ' ));
352+ }
353+
354+ /**
355+ * Tag the image name into a repository
356+ *
357+ * @param string $image image ID
358+ * @param string $repo The repository to tag in
359+ * @param string|null $tag The new tag name
360+ * @param boolean $force 1/True/true or 0/False/false, default false
361+ * @return Promise Promise<null>
362+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#tag-an-image-into-a-repository
363+ */
364+ public function imageTag ($ image , $ repo , $ tag = null , $ force = false )
365+ {
366+ return $ this ->browser ->post ($ this ->url ('/images/%s/tag?repo=%s&tag=%s&force=%u ' , $ image , $ repo , $ tag , $ force ))->then (array ($ this ->parser , 'expectEmpty ' ));
367+ }
368+
369+ /**
370+ * Remove the image name from the filesystem
371+ *
372+ * @param string $image image ID
373+ * @param boolean $force 1/True/true or 0/False/false, default false
374+ * @param boolean $noprune 1/True/true or 0/False/false, default false
375+ * @return Promise Promise<null>
376+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#remove-an-image
377+ */
378+ public function imageRemove ($ image , $ force = false , $ noprune = false )
379+ {
380+ return $ this ->browser ->delete ($ this ->url ('/images/%s?force=%u&noprune=%u ' , $ image , $ force , $ noprune ))->then (array ($ this ->parser , 'expectEmpty ' ));
381+ }
382+
383+ /**
384+ * Search for an image on Docker Hub.
385+ *
386+ * @param string $term term to search
387+ * @return Promise Promise<array> list of image search result objects
388+ * @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#search-images
389+ */
390+ public function imageSearch ($ term )
391+ {
392+ return $ this ->browser ->get ($ this ->url ('/images/search?term=%s ' , $ term ))->then (array ($ this ->parser , 'expectJson ' ));
393+ }
394+
281395 /**
282396 * Sets up an exec instance in a running container id
283397 *
@@ -346,4 +460,14 @@ private function json($data)
346460 }
347461 return json_encode ($ data );
348462 }
463+
464+ private function authHeaders ($ registryAuth )
465+ {
466+ $ headers = array ();
467+ if ($ registryAuth !== null ) {
468+ $ headers ['X-Registry-Auth ' ] = base64_encode ($ this ->json ($ registryAuth ));
469+ }
470+
471+ return $ headers ;
472+ }
349473}
0 commit comments