stevec
stevec

Reputation: 52198

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

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

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?

Upvotes: 8

Views: 27888

Answers (4)

Mobile
Mobile

Reputation: 11

Coming a little late but here is my own solution: I always need to amd64 because all of our servers are amd64, so to make my life easier I just wrote a function to always use this parameter on "docker run":

docker() {
    if [[ "$1" == "run" ]]; then
        shift
        command docker run --platform linux/amd64 "$@"
    else
        command docker "$@"
    fi
}

Basically it will overwrite docker command with this function, and what this function does is overwrite "docker run" to add the --platform linux/amd64 parameter, all other commands will remain intact.

Upvotes: 1

d42k5742
d42k5742

Reputation: 21

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.

Upvotes: 2

Sandeep Kumar
Sandeep Kumar

Reputation: 71

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

Upvotes: 7

guppie70
guppie70

Reputation: 51

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!

Upvotes: 3

Related Questions