Docker 映像在 Intel mac 上运行,但不在 M1 mac 上运行 [英] Docker image runs on Intel mac but not M1 mac

查看:41
本文介绍了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?

推荐答案

我的 M1 macbook 上的 Java 容器也有很多问题.对于您的问题,也许您需要创建自己的 docker 镜像:

I have a lot of problems with Java containers too on my M1 macbook. For your problem, maybe you need to create your own docker image:

Dockerfile

FROM --platform=linux/arm64/v8 ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive
EXPOSE 8080

RUN apt update \
    && apt upgrade -y \
    && apt install -y openjdk-13-jre git \
    && apt clean

RUN mkdir -pv /app && cd /app && \
    git clone https://github.com/spring-guides/gs-spring-boot.git && \
    cd /app/gs-spring-boot/initial && ./gradlew build

WORKDIR /app/gs-spring-boot/initial

ENTRYPOINT [ "./gradlew", "bootRun" ]

构建镜像

docker build -t test .

运行容器

docker run --rm -p 8080:8080 test

在浏览器上访问 http://localhost:8080/,您的 Spring-Boot 应用程序在没有 Rosetta 2 的情况下运行.

Go to http://localhost:8080/ on your browser and your Spring-Boot application is running without Rosetta 2.

免责声明:我不是 Java 开发人员,我的 Dockerfile 用于概念验证.

Disclaimer: I'm not a Java developer and my Dockerfile is for Proof of Concept purpose.

请记住,您的 Docker 映像是针对 ARM64 架构构建的.如果你想在 Intel/AMD 处理器上运行这个容器,你必须在你的 Dockerfile 上更改 FROM --platform=linux/amd64 ubuntu:20.04.

Remember that your Docker image is builded to ARM64 architecture. If you wanna run this container on a Intel/AMD processor, you have to change FROM --platform=linux/amd64 ubuntu:20.04 on your Dockerfile.

这篇关于Docker 映像在 Intel mac 上运行,但不在 M1 mac 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆