带有不同拱门的Docker图像很好,为什么?

发布于 2025-01-31 02:36:41 字数 1184 浏览 4 评论 0原文

我试图弄清楚为什么我使用英特尔MacBook构建的Docker映像在我的M1 MacBook上作品(它确实吐出了有关平台的警告,但仍在运行)。

在我的Intel机器上,我创建了一个简单的Python脚本Dockerfile,并构建并推动了图像。

# hello_world.py
def hello_world():
    print("hello world")

if __name__ == "__main__":
    hello_world()

对于Dockerfile ...

FROM python:3.9-buster
WORKDIR /src
COPY ./hello_world.py /src/hello_world.py
CMD ["python3", "hello_world.py"]

对于构建和推动

$ docker build -t jduran9987/hello_world:single-arch .
$ docker push jduran9987/hello_world:single-arch

DockerHub,支持的OS/Arch说Linux/AMD64,如预期。

但是,我能够在我的M1机器上成功运行Hello_world.py脚本,尽管我确实收到了有关不同平台的警告。

我感到困惑,因为我不希望能够在M1上运行图像(linux/arm64拱门)。有人可以给我一些见解吗?

  • 仅供参考,我知道如何构建多个架构图像,只是为何使用一个拱门在另一个拱门上构建的图像感到困惑。

I am trying to figure out why a Docker image that I built using my Intel Macbook works on my M1 Macbook (It does spit out a warning about the platform but still runs).

On my Intel machine, I created a simple Python script, Dockerfile, and build and pushed the image.

# hello_world.py
def hello_world():
    print("hello world")

if __name__ == "__main__":
    hello_world()

For the Dockerfile...

FROM python:3.9-buster
WORKDIR /src
COPY ./hello_world.py /src/hello_world.py
CMD ["python3", "hello_world.py"]

For the build and push

$ docker build -t jduran9987/hello_world:single-arch .
$ docker push jduran9987/hello_world:single-arch

On DockerHub, the supported OS/ARCH says linux/amd64 as expected.

enter image description here

However, I am able to successfully run the hello_world.py script on my M1 machine, though I do receive a warning about the different platforms.

enter image description here

I am confused because I was not expecting to be able to run the image on my M1 (linux/arm64 arch). Can someone give me some insight into this?

  • FYI, I know how to build multi-arch images, just confused as to why an image that was built using one arch works on another.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文