- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run amd64 Docker images on the arm64 host platform?
Before knowing how to run amd64 docker images on the arm64 host platform, we must know what this means. There is a term called multi-architecture or multi-platform docker container images. These images contain the ability to run on various base or host architectures provided at the time of containerization of the images.
Need of Multiplatform images
Suppose you are a DevOps engineer and you have to prepare a web-server for an IT company. You have an amd64 host platform but when you handed over the image to the company you came to know that the company only works on the amr64 host platform. Even though you prepared the web-server very well but it will fail to work on the arm machine because the container image is specifically built for the amd64 architecture. This problem introduces us to the world of multi-architecture docker images.
How to Check the Architecture of the Images?
Commands for Ubuntu, Alpine, Busybox, and Raspbian images.
Example
$ docker run ubuntu uname -m output: x86_64 $ docker run alpine uname -m output: x86_64 $ docker run busybox uname -m output: x86_64 #docker run raspbian/stretch uname -m armv7l
Creating Multiplatform Images
Stepwise execute the below process for creating a multiplatform image using the dockerfile and the docker builder functionality provided by the docker daemon.
Step 1: Create a dockerfile for the image building.
Here we have created a minimalistic dockerfile.
Example
#Here we will use the busybox as the base image FROM busybox:latest RUN echo "hello this is busybox" CMD ["uname" "-m"]
Step 2: Build the created Dockerfile
Now we will build this dockerfile using the buildx functionality. Usually, we create images using the “docker build” but here we will use “docker buildx” because it provides the developer much more flexibility in building.
Example
$ docker buildx build \ --platform linux/amd64,linux/arm64 \ --push \ -t <dockerhub_Username>/buildx_image_new .
Output
[+] Building 34.0s (16/16) FINISHED => [internal] booting buildkit 4.4s => => pulling image moby/buildkit:buildx-stable-1 3.2s => => creating container buildx_buildkit_mynewbuilder0 1.2s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 162B 0.1s => [linux/arm64 internal] load metadata for docker.io/library/busybox:latest 8.3s => [linux/arm/v6 internal] load metadata for docker.io/library/busybox:latest 7.6s => [linux/amd64 internal] load metadata for docker.io/library/busybox:latest 8.4s => [auth] library/busybox:pull token for registry-1.docker.io 0.0s => [linux/amd64 1/2] FROM docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d65 0.1s => => resolve docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d65f5757a954831 0.1s => [linux/arm64 1/2] FROM docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d65 0.1s => => resolve docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d65f5757a954831 0.1s => [linux/arm/v6 1/2] FROM docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d6 3.2s => => resolve docker.io/library/busybox:latest@sha256:fcd85228d7a25feb59f101ac3a955d27c80df4ad824d65f5757a954831 0.1s => => sha256:1f034cc8a3763179d1066acbd5441a02c518c2697c7615def9a6edce981b70d1 953.68kB / 953.68kB 3.0s => => extracting sha256:1f034cc8a3763179d1066acbd5441a02c518c2697c7615def9a6edce981b70d1 0.1s => CACHED [linux/arm64 2/2] RUN echo "hello this is busybox" 0.0s => CACHED [linux/amd64 2/2] RUN echo "hello this is busybox" 0.0s => [linux/arm/v6 2/2] RUN echo "hello this is busybox" 0.3s => exporting to image 17.4s => => exporting layers 0.1s => => exporting manifest sha256:ff2057bc3b087bf2b731a0063b44f74d24a2b5e48ee9902547421574d7ec9bf9 0.0s => => exporting config sha256:e4550dd445e9e1fe2cbe5c18fb745f795cf8fe9e0d17309be9664e33c2ef8d9a 0.0s => => exporting manifest sha256:360c05bf0afe9057b778991d1ed29a5fead857f67b555d58ef4a2db39caf5532 0.0s => => exporting config sha256:b8c5096ae3829ec9e0a02d73654a15883f31fab05189039e3d680d637d642761 0.0s => => exporting manifest sha256:cd5f9f98ba829e12c82ab63b1be7432a70125aadbb9a89dc51609d6e9cee6a23 0.0s => => exporting config sha256:2c550e8596608e89b705738ee6e20543bede26bff74fcf2a82baad72ae215a48 0.0s => => exporting manifest list sha256:d74f387cab65b336185b91491aff79c263018fb6d1acd6e0a7c37537333cc1e3 0.0s => => pushing layers 13.6s => => pushing manifest for docker.io/<dockerhub_Username>//buildx_image_new:latest@sha256:d74f387cab65b336185b91491aff79c 3.5s => [auth] <dockerhub_Username>//buildx_image_new:pull,push token for registry-1.docker.io 0.0s => [auth] <dockerhub_Username>//buildx_image:pull <dockerhub_Username>//buildx_image_new:pull,push token for registry-1.docker.io 0.0s
Now go to the docker hub and log into your username and check in the repository if any image is present with the name you uploaded or pushed.
If you face any problem in the above command execution then first login to your docker hub on the terminal using the “docker login” command and then enter “username” and “password” according.
Using the above steps we have created a multiplatform docker image on an “amd64” host architecture. Now we can use this docker image on “linux/amd64” and also on “linux/arm64”.
Create Container on amd Host Platform
By using the below-given commands you can now create a busybox container on the amd host platform. First, you need to pull the image to the host machine using “docker pull” then you can containerize using “docker run”.Use the same docker hub username you used during the creation of the image and push it to the repository.
Example 1
$ docker pull <dockerhub_Username>/buildx_image_new
Output
Using default tag: latest latest: Pulling from <dockerhub_Username>/buildx_image_new Digest: sha256:d74f387cab65b336185b91491aff79c263018fb6d1acd6e0a7c37537333cc1e3 Status: Downloaded newer image for <dockerhub_Username>/buildx_image_new:latest docker.io/<dockerhub_Username>/buildx_image_new:latest
Let’s check if the image is pulled from the repository.
Example 2
$docker images
Output
<dockerhub_Username>/buildx_image_new latest e4550dd445e9 5 days ago 1.24MB
After the image has been pulled successfully, let's run this image on this amd system.
Example 3
$ docker run –it \ --name host_amd64 \ <dockerhub_Username>/buildx_image
Output
x86_64
Create a container on arm Host Platform
Here we have used a Raspberry pi because it works on the arm architecture.
Step 1: Install the docker client and docker container on the raspbian OS.
First, update and upgrade the apt-get repository.
$sudo apt-get update && sudo apt-get upgrade
Now download the get_docker.sh script.
$curl -fsSL get.docker.com -o get-docker.sh
Check if the script is downloaded or not using “ls”.
$ls
Now execute this script to install docker on the raspberry pi machine.
$sh get-docker.sh
Now you need to append the raspbian user to the docker group.
$sudo usermod -aG docker $USER
Restart the raspbian OS to execute all the changes.
$sudo restart
Step 2: Now pull the same docker image
Example
$ docker pull <dockerhub_Username>/buildx_image
Output
Using default tag: latest latest: Pulling from <dockerhub_Username>/buildx_image_new 1f034cc8a376: Pull complete 92d2a98e1f6d: Pull complete Digest: sha256:d74f387cab65b336185b91491aff79c263018fb6d1acd6e0a7c37537333cc1e3 Status: Downloaded newer image for <dockerhub_Username>/buildx_image_new:latest docker.io/<dockerhub_Username>/buildx_image_new:latest
Step 3: Now run this docker image
Example
$ docker run –it \ --name host_arm \ <dockerhub_Username>/buildx_image
Output
armv7l
This is the way to run amd created images on the arm host platform. If this does not run the image on the raspbian os then check the architecture of the raspberry pi using the command “uname –m” and add this architecture during the creation of the “buildx image”.
- Related Articles
- How to run Gunicorn on Docker?
- How to copy Docker images from one host to another without using a repository?
- How to run Linux libraries on Docker on Windows?
- How to list images in Docker?
- How to copy files from host to Docker container?
- How to run splash using Docker toolbox?
- Copying files from Docker container to Host
- How to get Docker containers to talk to each other while running on my local host?
- How can Tensorflow be used to run the classifier on a batch of images?
- How to run a command inside Docker Container?
- Connecting From Docker Containers to Resources in Host
- Docker host network vs bridge network
- How do I run a command on an already existing Docker container?
- How to get a Docker container's IP address from the host?
- How to run a Docker image in IBM Cloud Functions?
