如何在 Intel Mac 的 Silicon Mac M1 上运行 Dockerfile

时间:2021-03-06 09:49:13

标签: macos docker dockerfile apple-silicon

我的母语不是英语,但我想在 Stack Overflow 上提问。 我是 Docker 的初学者。

我正在尝试在 Intel mac 的 Silicon Mac M1 上设置开发环境。

#!/bin/sh
set -e
. ./env.list
# Build Docker image
# docker pull store/ibmcorp/db2_developer_c:11.1.4.4-x86_64
docker build -t ${REPOSITORY}:${TAG} .

# DOCKERFILE
FROM store/ibmcorp/db2_developer_c:11.1.4.4-x86_64
RUN yum -y update && yum clean all
RUN curl ftp://ftp.pbone.net/mirror/vault.centos.org/7.8.2003/os/x86_64/Packages/glibc-common-2.17-307.el7.1.x86_64.rpm > /tmp/glibc-common.rpm
RUN rm -f /etc/localtime
RUN mkdir /var/custom

我得到如下错误

Step 2/30 : RUN yum -y update && yum clean all
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

我已经添加了 --platform linux/amd64 另一个 docker run 命令

#!/bin/bash
. ./env.list
docker rm -f api-db
docker run --name api-db -h db2server --restart=always --detach --privileged=true -p 50000:50000 -p 55000:55000 --platform linux/amd64 --env-file env.list sample-app:v1.0

我应该为 dockerfile 做什么?

非常感谢您的阅读。

祝你有美好的一天! :)

1 个答案:

答案 0 :(得分:1)

Apple M1 是 arm64v8 指令集处理器,因此您不能在没有仿真的情况下在其上运行 amd64 (X86_64)。一般来说,如果设置了基于 bitfmt 的仿真(并且在带有 intel CPU 的 maxOS 上已经设置),Do​​cker 可以模拟其他架构,但是 M1 上的 amd64 仿真是还不稳定。这意味着在一段时间内,您将被限制使用“arm64”图像。

要在构建过程中为您的架构获取正确的图像,您需要添加以下内容。

FROM --platform linux/arm64 <image name>

你需要检查一下是否有db2 arm开发环境的镜像

docker pull --platform linux/arm64 store/ibmcorp/db2_developer_c