Bender
Bender

Reputation: 69

How to pull docker image from nexus repository with rest api

it is possible to download docker image (as a zip file or tar file) from nexus repository using the rest api, if yes how to?

if not possible how to pull image without docker-cli from private registry?

thank all

Upvotes: 1

Views: 2346

Answers (1)

BMitch
BMitch

Reputation: 265070

An image is a collection of layers and metadata, typically packaged as gziped tar files and json respectively. The full definition of an OCI image is available at OCI's image-spec. These are individually pushed to the registry with multiple API calls for the various blobs (layers and config json) and manifests (json) defined by OCI's distribution-spec. All of the objects are pushed and retrieved from the registry using their digest since it is a content addressable store (CAS), with the exception of pulling a manifest by tag.

You can implement all of these API's yourself. Typically the more complicated part is the authentication since there's both basic and bearer tokens, and not everyone implements the bearer tokens the same way. Several client side implementations of this API exist in addition to the runtimes like containerd (used by Docker). Those include go-containerregistry from Google, skopeo from RedHat, and regclient from myself. The equivalent of what you're trying to do with regclient looks like:

$ regctl image export nexus.example.org/group/repo:tag export.tar
$ tar -tvf export.tar
-rw-r--r-- 0/0              30 1969-12-31 19:00 oci-layout
-rw-r--r-- 0/0             329 1969-12-31 19:00 index.json
drwxr-xr-x 0/0               0 1969-12-31 19:00 blobs/sha256
-rw-r--r-- 0/0            1638 1969-12-31 19:00 blobs/sha256/21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3
-rw-r--r-- 0/0            1471 1969-12-31 19:00 blobs/sha256/c059bfaa849c4d8e4aecaeb3a10c2d9b3d85f5165c66ad3a4d937758128c4d18
-rw-r--r-- 0/0         2818413 1969-12-31 19:00 blobs/sha256/59bf1c3509f33515622619af21ed55bbe26d24913cedbca106468a5fb37a50c3
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/e047bc2af17934d38c5a7fa9f46d443f1de3a7675546402592ef805cfa929f9d
-rw-r--r-- 0/0            1484 1969-12-31 19:00 blobs/sha256/14f3026d927f00e733daa66d4dd23ef30f93f64d47b43df08ef45e33e67d2d4a
-rw-r--r-- 0/0         2631421 1969-12-31 19:00 blobs/sha256/e4a43de54da9e309482f6762f0c11f5f547cd8fd61a49c5f158453066162023e
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/8483ecd016885d8dba70426fda133c30466f661bb041490d525658f1aac73822
-rw-r--r-- 0/0            1484 1969-12-31 19:00 blobs/sha256/78571b13081b3f0e2737073f044b9b37aae887b4196f673fdd0dc03fa4a1b7bc
-rw-r--r-- 0/0         2434764 1969-12-31 19:00 blobs/sha256/5480d2ca1740c20ce17652e01ed2265cdc914458acd41256a2b1ccff28f2762c
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/c74f1b1166784193ea6c8f9440263b9be6cae07dfe35e32a5df7a31358ac2060
-rw-r--r-- 0/0            1486 1969-12-31 19:00 blobs/sha256/8e1d7573f448dc8d0ca13293b1768959a2528ff04be704f1f3d35fd3dbf6da3d
-rw-r--r-- 0/0         2715434 1969-12-31 19:00 blobs/sha256/9b3977197b4f2147bdd31e1271f811319dcd5c2fc595f14e81f5351ab6275b99
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/2689e157117d2da668ad4699549e55eba1ceb79cb7862368b30919f0488213f4
-rw-r--r-- 0/0            1469 1969-12-31 19:00 blobs/sha256/6c6b5850b9e7ecbae567a028e2f5600a255914e3cc2682951103fc0ae973ff32
-rw-r--r-- 0/0         2827117 1969-12-31 19:00 blobs/sha256/e6889e0d66307a4b916fc844f2dcbc03245c63bc4189dd3e88126d9dcf2f9231
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/2042a492bcdd847a01cd7f119cd48caa180da696ed2aedd085001a78664407d6
-rw-r--r-- 0/0            1473 1969-12-31 19:00 blobs/sha256/00c822ab1e0a9010e86bbbba6993a29c528d2b6727c025660e9f0d47dd92f65c
-rw-r--r-- 0/0         2814780 1969-12-31 19:00 blobs/sha256/159b5dcb1717c815c76ff5ea1db730e18e8609c9090238e43282856db9e71f47
-rw-r--r-- 0/0             528 1969-12-31 19:00 blobs/sha256/49e322ab6690e73a4909f787bcbdb873631264ff4a108cddfd9f9c249ba1d58e
-rw-r--r-- 0/0            1469 1969-12-31 19:00 blobs/sha256/f68b386c3067e1fe941e4350a496fa0dbc6e134ae8b9c29a608c5c8b1ba76f7f
-rw-r--r-- 0/0         2605944 1969-12-31 19:00 blobs/sha256/d6baca485f3d0f7c77221be60fbef5db014a5ef9d8f53db4a310c947c690d189

The above tar file structure is defined in the OCI image layout.

Upvotes: 2

Related Questions