Docker Community Forums

Share and learn in the Docker community.

Building Docker Container on x86_64 to use on aarch64

Hello, I am trying to develop python code for projects that work on my Ubuntu 18.04 x86_64 architecture and then run the same code on an NVIDIA Xavier which is aarch64 architecture. The main issue is that the code requires certain versions of python packages which I am unable to download onto the Xavier; the problem apparently being that the arm architecture versions of those package versions have not been made yet. The most important package version discrepancy being with pytorch, torchvision, and opencv.

I recently discovered Docker, and it sounded like I could work around this. Since I’m new, I’m a bit unsure of the procedure (or if what I want to do is actually possible):

  • Write python code that depends on certain versions of package on my x86_64 Ubuntu 18.04 machine.
  • Execute this same python code (which depends on the same versions of packages) on the arm64 machine

I have searched online and I’m really not sure if the references I’m looking at do exactly what I stated above. I’ve seen some websites talking about building arm containers on x86 machines, but I feel like what I need is to build an x86 container and have it run on arm architecture? It’d be great to get confirmation/denial that what I want to do is possible and then get pointed to the right instruction set (or have it explained to me). Thank you!

Download the latest version of Docker Desktop.

Follow the on-screen instructions to complete the installation process. After you have successfully installed Docker Desktop, you will see the Docker icon in your task tray.

Click About Docker Desktop from the Docker menu and ensure you have installed Docker Desktop version (33772) or higher.


Build and run multi-architecture images
Run the command docker buildx ls to list the existing builders. This displays the default builder, which is our old builder.

$ docker buildx ls

default * docker
default default running linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
Create a new builder which gives access to the new multi-architecture features.

$ docker buildx create --name mybuilder

Alternatively, run docker buildx create --name mybuilder --use to create a new builder and switch to it using a single command.

Switch to the new builder and inspect it.

$ docker buildx use mybuilder

$ docker buildx inspect --bootstrap

[+] Building 2.5s (1/1) FINISHED
=> [internal] booting buildkit 2.5s
=> => pulling image moby/buildkit:master 1.3s
=> => creating container buildx_buildkit_mybuilder0 1.2s
Name: mybuilder
Driver: docker-container

Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running

Platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
Test the workflow to ensure you can build, push, and run multi-architecture images. Create a simple example Dockerfile, build a couple of image variants, and push them to Docker Hub.

$ mkdir test && cd test && cat < Dockerfile

FROM ubuntu
RUN apt-get update && apt-get install -y curl
COPY . .
$ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .

[+] Building 6.9s (19/19) FINISHED

=> => pushing layers 2.7s
=> => pushing manifest for 2.2
Where, username is a valid Docker username.

Thanks for the detailed response! I did a search and it seems like there is no Docker desktop for Ubuntu? That said, I was able to install Docker 19.03 and buildx. I was able to get through all of the commands through
$ docker buildx inspect --bootstrap

However, I did not have linux/arm/v7, linux/arm/v6 listed under platforms. But I did have linux/amd64 and linux/arm64, which is the architecture I need.

I created the docker file, built, and pushed. I had to remove the “linux/arm/v7” in the build line and it successfully built and pushed.

I went to my aarch64 machine and pulled the image and was able to run it with no issues.

I’m now wondering what the steps are so that I can install the correct python version and packages and run my python code on my aarch64 machine.

I am currious if the bot user lewish95 will find a roughly suiting answer for that question as well :slight_smile:

Wait really, he’s a bot? It feels awkward thanking a bot for a detailed response. (Well, my question about running some python code is still here.)

So far his responses are direct google search result for keywords that usualy roughly match some keywords of the title or post body. Generally the answers are more confusing than helping to other users. Heck the other day there was a thread posted here and on Stack Overflow. lewish95 pasted the final response from SO as an answer in the thread here cough.

Since today I have not seen one answer with a single own written word of his/her/it. This makes me believe that it’s a bot :slight_smile: