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

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

问题描述

我已经为CLI实用程序创建了一个Dockerfile,它在我的Linux笔记本电脑上运行良好.我尝试在装有Docker的Raspberry Pi上运行该容器,但无法正常工作.

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?

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

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?

一个快速的答案是不可能创建一个支持多种架构的图像.但是,似乎一个图像将满足多种体系结构,因为您实际上正在与 a进行交互清单文件.清单文件可根据请求镜像的Docker客户端充当指向正确镜像的指针.

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.

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

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 这三个命令可以解决问题(假设您使用的是x86_64计算机)

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]

注意::取决于您是否使用多体系结构基本映像,您可能不需要docker manifest annotate步骤.

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

注意::在推送清单文件(即docker manifest push ...)时,请确保使用--purge选项;链接的文章中未对此进行讨论.如果您计划使用稍后会被重用的标签(例如latest),则不使用--purge会引起您的痛苦.

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天全站免登陆