如何制作多架构 Docker 镜像? [英] How do I make multi-arch Docker images?

查看:40
本文介绍了如何制作多架构 Docker 镜像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 CLI 实用程序创建了一个 Dockerfile,它在我的 Linux 笔记本电脑上运行良好.我尝试在安装了 Docker 的 Raspberry Pi 上运行容器,但它不起作用.

我知道无数公司创建图像来支持多种架构,他们是如何做到这一点的?

我想知道,因为我希望 CLI 的容器可以部署到 Raspberry Pi 以及我的 Linux 笔记本电脑.

解决方案

我知道其他公司创建图像来支持多种架构,他们是如何做到这一点的?

简单的回答是,不可能创建一个支持多种架构的单一镜像.但是,看起来好像一个图像将满足多种架构,因为您实际上是在与 a清单文件.清单文件充当指向基于请求图像的 Docker 客户端的正确图像的指针.

例如,您可以在 x86_64 平台(例如您的 Linux 笔记本电脑) 上运行 docker build,然后在 armv7l 上再次运行 平台(例如树莓派),将创建​​两个完全不同的图像.生成的图像应具有特定于平台的名称并推送到您的 Docker 图像存储库(例如 hub.docker.com).

完成后,您将需要启用实验模式 在 Docker CLI 中,以及 创建并上传一个清单文件,其具有指向相应平台特定图像的平台中性名称.

TL;DR这三个命令可以解决问题(假设您在 x86_64 机器上工作)

docker manifest create <图像参考>[<图像参考>...]docker manifest annotate <new-list-ref-name><图像参考>--os linux --arch armdocker manifest push [ - 清除]

注意:根据您是否使用多架构基础镜像,您可能不需要 docker manifest annotate 步骤.

注意:推送清单文件(即docker manifest push ...)时,请务必使用--purge选项;它没有在链接的文章中讨论.不使用--purge,如果你打算使用一个以后会重复使用的标签(例如latest),会让你心痛.>

I've created a Dockerfile for a CLI utility, and it works great on my Linux laptop. I tried running the container on a Raspberry Pi with Docker installed, but it won't work.

I know myriad companies create images to support multiple architectures, how are they doing this?

I want to know, because I want the container for the CLI to be deployable to a Raspberry Pi, as well as my Linux laptop.

解决方案

I know other companies create images to support multiple architectures, how are they doing this?

The quick answer is that it is NOT possible to create a single image that will support multiple architectures. However, it appears as if one image will satisfy multiple architectures because you are actually interacting with a manifest file. A manifest file acts as a pointer to the correct image based on the Docker client that requested the image.

For example, you can run docker build on an x86_64 platform (e.g. your Linux laptop) and again on an armv7l platform (e.g. a Raspberry Pi), and two completely different images will be created. The resulting images should be given platform specific names and pushed to your Docker image repository (e.g. hub.docker.com).

Once that has been completed, then you will need to enable experimental mode in the Docker CLI, and create and upload a manifest file with a platform neutral name that points to the corresponding platform specific images.

TL;DR These three commands will do the trick (assuming you are working from the x86_64 machine)

docker manifest create <new-list-ref-name> <image-ref> [<image-ref>...]
docker manifest annotate <new-list-ref-name> <image-ref> --os linux --arch arm
docker manifest push <new-list-ref-name> [--purge]

NOTE: Depending on whether or not you are using a multi-arch base image, you may not need the docker manifest annotate step.

NOTE: When pushing a manifest file (i.e. docker manifest push ...), be sure to use the --purge option; it is not discussed in the linked articles. Not using --purge, will cause you heartache if you plan on using a tag that will be reused at a later time (e.g. latest).

这篇关于如何制作多架构 Docker 镜像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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