How to give parameter to a docker image in docker file so that it still works in Apple M1 Machine

Viewed 1508

I used to be able to download openjdk:8-jdk-slim as below

docker run -it --name my-container openjdk:8-jdk-slim

After moving to Apple M1 MacBook Pro, I have to use this parameter --platform linux/amd64 as stated in https://docs.docker.com/docker-for-mac/apple-silicon/

docker run -it --platform linux/amd64 --name my-container openjdk:8-jdk-slim

But for a Dockerfile I have

FROM openjdk:8-jdk-slim

// Other codes

How can I add the needed parameter to it, so that the Dockerfile still work on my Apple M1 MacBook Pro?

1 Answers

You can add --platform option to a FROM statement as well:

FROM --platform=linux/amd64 openjdk:8-jdk-slim
...

It's mentioned in the Dockefile reference:

The optional --platform flag can be used to specify the platform of the image in case FROM references a multi-platform image. For example, linux/amd64, linux/arm64, or windows/amd64. By default, the target platform of the build request is used. Global build arguments can be used in the value of this flag, for example automatic platform ARGs allow you to force a stage to native build platform (--platform=$BUILDPLATFORM), and use it to cross-compile to the target platform inside the stage.

Related