Docker 映像在 Intel mac 上运行,但不在 M1 mac 上运行

Docker 映像在 Intel mac 上运行,但不在 M1 mac 上运行

问题描述:

我们有一个在 Docker 容器中运行的 Java Spring Boot 应用程序.它基于 openjdk:13-jdk-alpine.我们将它部署到 Linux 机器上,但我们也能够在 Windows 机器以及基于 Intel 的 iMac 上本地运行它.

We have a Java Spring Boot application that runs in a Docker container. It is based on openjdk:13-jdk-alpine. We deploy it to Linux machines, but we are also able to run it locally on Windows machines, as well as on an Intel-based iMac.

不过,我们发现它无法在基于 ARM 的 MacBook Pro 上正常运行.我们得到的异常是基本的 Java 错误,例如找不到符号 Java.class[]",以及其他看起来像 JVM 关闭的东西.

We have found, though, that it cannot run properly on an ARM-based MacBook Pro. The exceptions we get are basic Java errors like "Can't find symbol Java.class[]," and other things that look like the JVM is off.

有没有办法构建一个适用于所有这些平台的 Docker 镜像,包括 M1 MacBook Pro?

Is there a way to build a Docker image that will work on all these platforms, including the M1 MacBook Pro?

使用 构建您的图像multiarch 支持以摆脱未来所有可能的架构故障.为了干净利落地做到这一点,请避免在 Dockerfile 中使用与平台相关的任何内容,老式的 Dockerfile 就可以了.

Build your images with multiarch support to get rid of all possible architecture failures in the future. To do this cleanly, avoid using anything related to the platform in your Dockerfile, just old-school Dockerfiles are ok.

如果你使用 github 和 github-actions,你可以查看 this 来构建您的图像并将它们推送到您的图像存储库中.这也可用于构建在 RaspberryPi 上运行的映像,如 SBC.

If you are using github and github-actions, you may check this to build your images and push them into your image repository. This can be also used for building images which work on RaspberryPi like SBCs.