在 Mac OSX 上构建的 Docker Image 无法在 AWS EC2 实例上运行 [英] Docker Image built on Mac OSX won't run on AWS EC2 instance

查看:28
本文介绍了在 Mac OSX 上构建的 Docker Image 无法在 AWS EC2 实例上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mac OSX 上构建的映像,使用 M1 处理器,部署到 EC2 实例.但是当脚本运行时它会产生错误:

Image built on Mac OSX with M1 processor, deployed to an EC2 instance. But when scripts are run it yields the error:

standard_init_linux.go:219: exec 用户进程导致:exec 格式错误

在 Stackoverflow 的其他地方,这被解释为操作系统架构不匹配.果然运行uname -m"在 EC2 实例上显示它是 x86_64,并且docker image inspect"显示具有架构 arm64 的容器.

Elsewhere on Stackoverflow, this is explained as a mismatch of OS architecture. Sure enough running "uname -m" on EC2 instance shows it to be x86_64, and "docker image inspect" shows the container to have architecture arm64.

这是我不明白的地方.uname -m"在我的 Mac 上也显示为 x86_64.那么容器如何继承不同的架构呢?

Here's what I don't understand. "uname -m" on my Mac shows that to be x86_64 too. So how does the container inherit a different architecture?

更重要的是,如何在 Mac 上构建可以在 EC2 上运行的映像?

More significantly, how do I build an image on my Mac that I can run on EC2?

Docker 文件很简单

Docker file is simply

FROM python
WORKDIR /
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY src /src

src 包含,目前,一些简单的 python 脚本,执行如下:

with src containing, currently, some simple python scripts, executed thus:

docker run container/name python test.py

这在我的 Mac 上运行良好,但在 AWS 上执行时会出现上述错误.

This works fine on my Mac, but gives the error above when executed on AWS.

推荐答案

好的.这就是正在发生的事情.我的 Mac 有新的 M1 芯片,我正在运行 Docker 桌面技术预览版.在引擎盖下,该芯片具有 arm64 架构,但通过 iTerm 和 VSCode 对其进行查询,它声称是 x86_64,因此当我发布问题时我感到困惑.这可能是因为这两个应用程序都在后台悄悄地通过英特尔模拟器运行,这就是对 uname 命令的响应.

OK. Here's what's happening. My Mac has the new M1 chip and I'm running the Tech Preview version of Docker Desktop. Under the hood the chip has the arm64 architecture, but interrogating it through iTerm and VSCode it claims to be x86_64 instead, hence my confusion when I posted the question. This is probably because both those apps are being quietly run through an Intel simulator behind the scenes and that's what's responding to the uname command.

但是,因为处理器实际上是 arm64,所以这是我从 Docker 中提取 Python 映像时的基本架构(我尝试了许多不同风格的 Python 版本 - 都得到了相同的结果).

However, because the processor is really arm64, that's the base architecture when I pull Python images from Docker (I tried lots of different flavours nd version of Python - all with the same results).

为了强制使用 amd64 AWS 兼容的镜像,我将 Dockerfile 的第一行更改为:

To force use of an amd64 AWS-compatible image I changed the first line of the Dockerfile to:

FROM --platform=linux/x86-64 python.

当来自此映像的容器在 Mac 上运行时会导致警告

When containers from this image are run on the Mac that causes a warning

警告:请求的镜像平台 (linux/amd64) 与检测到的主机平台 (linux/arm64/v8) 不匹配,并且没有请求特定的平台

但这只是一个警告,脚本运行(大概是通过英特尔模拟器重定向回来.脚本现在在 EC2 实例上运行没有问题(或警告).

but it's just that, a warning, and the script runs (presumably by redirecting back through the Intel simulator. The scripts now run without problem (or warning) on the EC2 instance.

这篇关于在 Mac OSX 上构建的 Docker Image 无法在 AWS EC2 实例上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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