Scenario
A multi-architecture image is an image repository that houses images of various architectures, catering to the needs of diverse hardware platform architectures.
When a container runtime pulls a multi-architecture image, it can automatically select an image that fits the current operating system architecture, thereby improving deployment efficiency.
This section introduces how to use the Cloud Container Repository to build multi-architecture images.
Before You Begin
• An instance of the Cloud Container Repository Enterprise Edition has been activated
• A local Docker client has been installed
Procedure
Building Multi-Architecture Images Through Dockerfile
1. This section takes a Go project as an example. Construct the following Dockerfile file:
ARG GOLANG_IMAGE="golang:1.19.3"
ARG BASE_IMAGE="alpine:3.16.5"
ARG TAG=1.0.0
FROM ${GOLANG_IMAGE} as build-cache
WORKDIR /build
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X my-app/version.Version=${TAG}" -o my-app .
FROM ${BASE_IMAGE}
COPY --from=build-cache /build/my-app /
WORKDIR /
ENTRYPOINT ["./my-app"]2. Log in to the instance of the Cloud Container Repository Enterprise Edition
docker login –username=<username> <enterprise edition instance address>
3. Use the docker buildx command to build and push multi-architecture images to the instance of the Cloud Container Repository Enterprise Edition
docker buildx build. -t <enterprise edition instance address>/<namespace>/<image repository>:<edition> --platform linux/amd64,linux/arm64 --push
Building a Multi-Architecture Image Using Existing Images
1. If there are already multiple single-architecture images locally, they can be combined into one multi-architecture image. This section demonstrates this using an arm64 architecture and an amd64 architecture Nginx image as examples.
2. Log in to the instance of the Cloud Container Repository Enterprise Edition
docker login –username=<username> <enterprise edition instance address>
3. Use the docker tag and docker push commands to push single-architecture images to the instance of the Cloud Container Repository Enterprise Edition respectively:
docker tag nginx:arm64 <enterprise edition instance address>/<namespace>/nginx:arm64 docker push <enterprise edition instance address>/<namespace>/nginx:arm64 docker tag nginx:amd64 <enterprise edition instance address>/<namespace>/nginx:amd64 docker push <enterprise edition instance address>/<namespace>/nginx:amd64
4. Use the docker manifest create command to create a Manifest List for a multi-architecture image:
docker manifest create <enterprise edition instance address> / <namespace>/nginx: multi \ <enterprise edition instance address>/<namespace>/nginx:arm64 \ <enterprise edition instance address>/<namespace>/nginx:amd64
5. Use the docker manifest push command to push the Manifest List to the instance of the Cloud Container Repository Enterprise Edition:
docker manifest push <enterprise edition instance address> / <namespace> / nginx: multi