Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build arm Container Image of Multi-Arch by Docker Desktop

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to build the arm container image of Multi-Arch by Docker Desktop". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Why is Docker doing this?

In November 2018 Amazon announced that the EC2 A1 instance uses AWS Graviton Processors, a 64-bit Arm Neoverse cores designed by AWS. A1 EC2 instances have optimized performance and low cost, resulting in cost savings of more than 45% compared with other EC2 instances. With the Docker Desktop technology preview, Docker will be able to more easily develop containers for running on Arm servers and devices. Using familiar Docker tools and processes, you can build, push, pull, and run mirrors to different architectures. There is no need to change the Dockerfiles and source code to build the mirrored version used on Arm. Simply use the new features to rebuild the image. Finally, Docker can be quickly extended to Edge and IoT, which will be an important step. Docker keeps an eye on developers and finds ways to make things easier.

How does it work?

Docker Desktop is available on macOS and Windows, and packaging and configuring a lot of things for users makes it easier to develop containers. That make developing containers extremely easy. Docker Desktop comes with hypervisors for the host OS. This hypervisor runs a lightweight Linux kernel (LinuxKit) that is part of Docker Desktop. This fast and lightweight container OS is encapsulated through QEMU emulator and runs binaries under any architecture through binfmt_misc. Arm submitted to support Docker's QEMU fork and help maintain the project. Docker Desktop will maintain the latest emulation support. The figure above shows QEMU emulation's support for arm/v6, arm/v7 and arm64 Docker images.

Docker Desktop Edge has introduced a new CLI command-buildx. Buildx allows you to build multi-arch images locally (and soon remotely), link manifest file, and then push it to registry-only one command is needed. With the included emulation, you can transparently build not just native images! Buildx adds a new builder instance (based on BuildKit) and then allows the Docker Desktops technology stack to run non-native binaries.

Why is it called buildx? This is an original name, and x stands for experience. When the new build features stabilizes in the future, the x integration will be removed into docker build command. Note that the nature of the buildx entity, features and flags will change later.

Start using

If there is no Docker Desktop, start by downloading it. Then follow the prompts to install. After installing Docker Desktop, you will see Docker icon in the taskbar, click "preferences", and then switch to the edge version. .

Confirm version 2.0.4.0 (33772) + by opening "About Docker Desktop".

Application example

Suppose you are interested in this great feature, let's look at some examples. List all builders:

~ ❯❯❯ docker buildx lsNAME/NODE DRIVER/ENDPOINT STATUS PLATFORMSdefault * docker default default running linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6

The default builder is currently used, based on the old builder. Let's create a new builder that will give you the ability to access multiple architectures:

~ ❯❯❯ docker buildx create-- name mybuildermybuilder~ ❯❯❯ docker buildx use mybuilder~ ❯❯❯ docker buildx inspect-- bootstrap [+] Building 2.5s (1 FINISHED 1) FINISHED = > [internal] booting buildkit 2.5s = > = > pulling image moby/buildkit:master 1.3s = > = > creating container buildx_buildkit_mybuilder0 1.2sName: mybuilderDriver: docker-containerNodes:Name: mybuilder0Endpoint: unix:///var/run/docker.sockStatus: runningPlatforms: linux/amd64 Linux/arm64, linux/arm/v7, linux/arm/v6

Here you create a new builder instance, name it mybuilder, switch over, and explore the information.

Note-bootstrap is not required, but is used to start container immediately.

Next we test the workflow. Confirm that we can build, push, and run multi-arch images.

Create a simple Dockerfile,build with several different images, and then push to Hub.

~ ❯❯❯ mkdir test & & cd test & & cat = > pushing layers 2.7s = > = > pushing manifest for docker.io/adamparco/demo:latest 2.2

Let's get to work! This-- platform flag tells buildx to create Intel 64-bit, Arm 32-bit, and Arm 64-bit architectures versions of Linux images. The-- push flag creates a multi-arch manifest and then pushes all its mirrors to Docker Hub. Use imagetools to inspect.

~ / test ❯❯❯ docker buildx imagetools inspect adamparco/demo:latestName: docker.io/adamparco/demo:latestMediaType: application/vnd.docker.distribution.manifest.list.v2+jsonDigest: sha256:2a2769e4a50db6ac4fa39cf7fb300fa26680aba6ae30f241bb3b6225858eab76Manifests: Name: docker.io/adamparco/demo:latest@sha256:8f77afbf7c1268aab1ee7f6ce169bb0d96b86f585587d259583a10d5cd56edca MediaType: application/vnd.docker.distribution.manifest.v2+json Platform: linux/amd64 Name: docker.io/adamparco/demo:latest@sha256:2b77acdfea5dc5baa489ffab2a0b4a387666d1d526490e31845eb64e3e73ed20 MediaType: application/vnd.docker.distribution.manifest.v2+json Platform: Linux/arm64 Name: docker.io/adamparco/demo:latest@sha256:723c22f366ae44e419d12706453a544ae92711ae52f510e226f6467d8228d191 MediaType: application/vnd.docker.distribution.manifest.v2+json Platform: linux/arm/v7

The image is now available for Docker Hub, and its tag is adamparco/demo:latest. You can run container on Intel laptops, Amazon EC2 A1 instances, Raspberry Pis, or others. Docker pulls the correct image that adapts to the current architecture, such as Raspberry Pis running 32-bit Arm version and EC2 A1 instance running 64-bit Arm version.

The SHA tags identifies a complete image variant and can also run different schema versions in Docker Desktop. We use SHA tag to run a mirror and then check to see if it is the architecture we expect.

~ / test ❯❯❯ docker run-- rm docker.io/adamparco/demo:latest@sha256:2b77acdfea5dc5baa489ffab2a0b4a387666d1d526490e31845eb64e3e73ed20 uname-maarch74~/test ❯❯❯ docker run-- rm docker.io/adamparco/demo:latest@sha256:723c22f366ae44e419d12706453a544ae92711ae52f510e226f6467d8228d191 uname-marmv7l

After the above command runs, we see that uname-m returns aarch74 and armv7l, which is what we expect. All building and running are done on my macOS development machine.

The technology stack described above would be difficult to do without Docker Desktop and buildx.

A more complex example, python flask web application, can show the architecture of the host.

~ ❯❯❯ docker buildx build-t adamparco/helloworld:latest-- platform linux/arm64-- push github.com/adamparco/helloworld [+] Building 69.1s (11 internal 11) FINISHED = > CACHED [internal] load git source github.com/adamparco/helloworld 0.0s = > [internal] load metadata for docker.io/library/python:3.7-alpine 0.5s = > [base 1Univer 1] FROM docker.io/library/python:3.7-alpine@sha256:b3957604aaf12d969 3.6s. = > > pushing layers 7.3s = > = > pushing manifest for docker.io/adamparco/helloworld:latest 0.3s

A single schema is specified, only 64-bit Arm. Now run and publish the service port as follows:

~ ❯❯❯ docker run-p5000UR 5000 adamparco/helloworld:latest... * Serving Flask app "hello" (lazy loading) * Environment: production * Debug mode: off * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Open the browser, load the address localhost:5000, and display:

In this way, you can simply use the Docker command to build and run multi-architecture images, and you can do these things through buildx. More new and powerful features will be added in future versions.

Amazon EC2 A1 Credits

For a limited time, sign up to beta.docker.com and receive a free credits that can use Amazon EC2 A1 instances to test and deploy Arm images.

That's all for "how Docker Desktop builds the arm container image of Multi-Arch". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report