如何为 docker 文件中的 docker 图像提供参数,使其在 Apple M1 Machine 中仍然有效
How to give parameter to a docker image in docker file so that it still works in Apple M1 Machine
我以前可以下载 openjdk:8-jdk-slim 如下
docker run -it --name my-container openjdk:8-jdk-slim
迁移到 Apple M1 MacBook Pro 后,我必须使用此参数 --platform linux/amd64
,如 https://docs.docker.com/docker-for-mac/apple-silicon/
中所述
docker run -it --platform linux/amd64 --name my-container openjdk:8-jdk-slim
但是我有一个 Dockerfile
FROM openjdk:8-jdk-slim
// Other codes
如何向它添加所需的参数,以便 Dockerfile 仍然可以在我的 Apple M1 MacBook Pro 上运行?
您也可以将 --platform
选项添加到 FROM
语句:
FROM --platform=linux/amd64 openjdk:8-jdk-slim
...
在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.
我以前可以下载 openjdk:8-jdk-slim 如下
docker run -it --name my-container openjdk:8-jdk-slim
迁移到 Apple M1 MacBook Pro 后,我必须使用此参数 --platform linux/amd64
,如 https://docs.docker.com/docker-for-mac/apple-silicon/
docker run -it --platform linux/amd64 --name my-container openjdk:8-jdk-slim
但是我有一个 Dockerfile
FROM openjdk:8-jdk-slim
// Other codes
如何向它添加所需的参数,以便 Dockerfile 仍然可以在我的 Apple M1 MacBook Pro 上运行?
您也可以将 --platform
选项添加到 FROM
语句:
FROM --platform=linux/amd64 openjdk:8-jdk-slim
...
在Dockefile reference中提到:
The optional
--platform
flag can be used to specify the platform of the image in caseFROM
references a multi-platform image. For example,linux/amd64
,linux/arm64
, orwindows/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.