How to use docker's Rosetta 2 x86_64 emulation when building a docker image on arm64 system architecture?

15.3k Views Asked by At

A dockerfile that builds successfully on a laptop with intel chip doesn't successfully build on a laptop that has an M2/arm/apple silicon chip.

How can I emulate the x86_64/amd64 environment on the arm based mac using Rosetta 2?

What I know so far

  • This comment on a GitHub issue mentions Docker Desktop will support emulation of x86_64 architecture in early 2023, so I updated Docker Desktop to the most recent version (4.17.0).
  • This comment shows a checkbox titled Use Rosetta for x86/amd64 emulation on Apple Silicon, which I checked (and also ensured Virtualization framework in turned on in the General settings tab is on.
  • I restarted both docker and terminal.

Is anything else necessary in order to make the docker build command build for x86_64 architecture using Rosetta 2 emulation, and how can I confirm that it's working as intended?

3

There are 3 best solutions below

0
guppie70 On

No that should suffice. Once your X64 docker container is started, you can enter the command line into the docker container and then type ps -ef. You should then see a list of processes running inside the docker. Each X64 process should be preceded by /rosetta/rosetta. Hope this helps!

0
Sandeep Kumar On

You can add --platform linux/amd64 to run (or build) an Intel image using emulation, in the latest docker version.

0
awaddell On

You can output the hardware platform with the uname command.

docker run --platform linux/amd64 --rm nginx uname -m
x86_64
docker run --rm nginx uname -m                   
aarch64

This is the host:

uname -mrspv
Darwin 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103 arm64 arm

Docker Desktop 4.21.1 with Use Rosetta for x86/amd64 emulation on Apple Silicon on in experimental settings.