ARTIFACTORY: How to push multi-arch images to Artifactory using docker buildx?

ARTIFACTORY: How to push multi-arch images to Artifactory using docker buildx?

AuthorFullName__c
Elina Floim
articleNumber
000005545
ft:sourceType
Salesforce
FirstPublishedDate
2023-01-09T09:53:56Z
lastModifiedDate
2023-01-09
VersionNumber
2

Docker introduced the principle of multi-arch builds to allow building software for different platforms. From Artifactory 7.21.3 and higher, Artifactory supports the docker buildx command, allowing you to create and upload Docker “fat manifest file” to your Docker repository in Artifactory. Docker buildx allows you to build and push multi-architecture images using a single command instead of having to build and push each of the architecture images separately.

The following steps need to be followed in order to create a multi-arch docker image and push it to Artifactory:

1. If you are not yet logged in to your Artifactory instance, log in to it:

$ docker login $ART_HOST
2. Create a Dockerfile which will be then referenced during the image push. The following commands should be run from the same directory containing the Dockerfile.

3. Create the docker context:
$ docker context create docker-buildx 
4. Create a builder instance pointing to the context created:
$ docker buildx create --use docker-buildx
5. Start the build using buildx stating the architectures and push it to Artifactory. For example:
$ docker buildx build --platform linux/amd64,linux/arm64 --tag "$ART_HOST/docker-virtual/docker-buildx:1.2.3" --push .

This is the content of the Dockerfile used in the above example:
FROM busybox
RUN uname -a

The build and push command generates the following output (based on the Dockerfile content):
[+] Building 9.3s (10/10) FINISHED
 => [internal] load .dockerignore                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                            0.0s
 => [internal] load build definition from Dockerfile                                                                                                                       0.0s
 => => transferring dockerfile: 64B                                                                                                                                        0.0s
 => [linux/arm64 internal] load metadata for docker.io/library/busybox:latest                                                                                              1.9s
 => [linux/amd64 internal] load metadata for docker.io/library/busybox:latest                                                                                              1.6s
 => [linux/amd64 1/2] FROM docker.io/library/busybox@sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c                                               0.1s
 => => resolve docker.io/library/busybox@sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c                                                           0.0s
 => => sha256:205dae5015e78dd8c4d302e3db4eb31576fac715b46d099fe09680ba28093a7a 2.59MB / 2.59MB                                                                             1.4s
 => => extracting sha256:205dae5015e78dd8c4d302e3db4eb31576fac715b46d099fe09680ba28093a7a                                                                                  0.1s
 => [linux/arm64 1/2] FROM docker.io/library/busybox@sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c                                               0.1s
 => => resolve docker.io/library/busybox@sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c                                                           0.0s
 => => sha256:f78e6840ded1aafb6c9f265f52c2fc7c0a990813ccf96702df84a7dcdbe48bea 2.00MB / 2.00MB                                                                             1.3s
 => => extracting sha256:f78e6840ded1aafb6c9f265f52c2fc7c0a990813ccf96702df84a7dcdbe48bea                                                                                  0.1s
 => [linux/arm64 2/2] RUN uname -a                                                                                                                                         0.2s
 => [linux/amd64 2/2] RUN uname -a                                                                                                                                         0.1s
 => exporting to image                                                                                                                                                     5.8s
 => => exporting layers                                                                                                                                                    0.1s
 => => exporting manifest sha256:0a3fc52350491236aed3fa26807c43a1a78bfe836c4eaa53426fd5fee7a35a5a                                                                          0.0s
 => => exporting config sha256:f1b01fd21509120ffbad062c0cc235f0902ac449a32924022085551b8b53178c                                                                            0.0s
 => => exporting manifest sha256:51ec72022c4f51d9b6064b4b73070da3f8fc9df8348e72b7dfc51846447ac523                                                                          0.0s
 => => exporting config sha256:87fbd1a8137d5b74bc08e0c6c22b6f0cba9e627391f4e3e08f61410aba2f5869                                                                            0.0s
 => => exporting manifest list sha256:f94826cb2416953bfa4115b4aff6ecfd42e0d22dbe4741bf2ccc63a7d2dc8405                                                                     0.0s
 => => pushing layers                                                                                                                                                      1.8s
 => => pushing manifest for ART_HOST/dev-docker/docker-buildx:1.2.3@sha256:f94826cb2416953bfa4115b4aff6ecfd42e0d22dbe4741bf2ccc63a7d2dc8405                         3.9s
 => [auth] dev-docker/docker-buildx:pull,push docker-buildx:pull token for ART_HOST


The result of the push will look like this:

User-added image

Relevant links:
Pushing Multi-Architecture Docker Images to Artifactory
docker context
docker buildx