

使用docker buildx打包发布多平台镜像 - 烦嚣的人
source link: https://www.cnblogs.com/wuyoucao/p/16461988.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

个人比较喜欢影视作品,下载了大量的剧集视频,有些文件的命名不规范,就需要重新命名,之前是用的一款 renamer 客户端软件,用起来不太爽就自己做了个 bs 架构的重命名软件并开源在 github:open-renamer,为了方便自己和别人使用,也做成了 docker 镜像发布到了 dockerhub 中供别人使用,由于本人只有 x86 架构的设备,因此也就是有 x86 的镜像包,结果最近有人需要 arm 版的镜像,所以呢就来研究下怎么在 x86 上打 arm 的镜像。
目前 docker 已经直接支持多平台同时打包,不过需要 20 版本及以后的,同时还要开启实验特性。
注意:本文 docker 版本基于 20.10.5
开启 docker 实验特性
首先需要开启 docker 的实验特性,在 docker 配置文件/etc/docker/daemon.json
中加入"experimental": true
,如下:
{ "registry-mirrors": [""], "experimental": true}
然后执行docker version
,当看到下面的内容说明开启成功了:
安装 buildx 插件
首先检查是否已经安装了 buildx 插件,命令:docker buildx version
,看到如下内容说明已经有 buildx 了
如果没有:
- 创建插件目录
mkdir ~/.docker/cli-plugins
- 下载插件到上面的目录中
wget -O ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.8.2/buildx-v0.8.2.linux-amd64
.注意这一步需要选择自己对应平台的二进制包 - 授予执行权限
chmod +x ~/.docker/cli-plugins/docker-buildx
官方安装文档:点击跳转
使用 dockerx 打包镜像
假设 Dockerfile 内容如下:
FROM node:lts-buster-slimWORKDIR /appRUN mkdir /app && echo "hello,world">/app/hello.txtCMD ["cat", "/app/hello.txt"]
注意:当打包到多平台时要注意 FROM 的镜像要存在于你指定的平台中,另外其中的所有操作都要能在多平台中执行
然后创建一个构建实例。默认情况下 buildx 不支持多平台打包
# 创建构建实例。通俗的讲,就是创建用于执行构建任务的节点docker buildx create --use --name build-node-example --driver docker-containerdocker buildx ls
然后就可以开始打包了
docker buildx build -t fleyx/open-renamer:0.8 --platform linux/amd64,linux/arm64 --push .
命令解释:
- -- platform:指定目标平台用","分隔
- -- push:将输出结果推送到远程。默认情况下多平台打包的镜像无法通过
docker images
查看
推送到远程要先用docker login
命令登录
然后到 hub.docker 查看刚刚推送的镜像就可以看到多版本支持了:
Recommend
-
15
Docker multi-arch with buildx. 7 minute read I use docker a lot, like… all the time, I use it locally and I run it on my servers, I use it for job and even in private. When working, I prefer to “bring my own images” t...
-
11
Preparation toward running Docker on ARM Mac: Building multi-arch images with Docker BuildX Original text by
-
17
时间序列预测库 prophet R版本 docker镜像打包
-
16
使用github action 配合 docker buildx 编译 arm64 docker-compose
-
6
使用buildx构建多平台可用Docker镜像 发表于 2020-04-07 | 分类于 技术控 |
-
15
Engineering Update: BuildKit 0.9 and Docker Buildx 0.6 Releases Kevin Alvarez Jul 28 20...
-
8
My Workflow One of the more urgent needs in the community was to automate the building of ARM wheels of PyTorch to utilize PyTorch on Nvidia Devices (e.g. Nvidia Jetson Nano) with CUDA enabled. Nvidia currently offers this bu...
-
17
-
10
写在前边 记录一下前阵子在X86_64平台使用Docker Buildx构建多平台镜像的办法,包含但不限于构建ARM镜像。
-
8
使用Docker buildx 为 .NET 构建多平台镜像 .NET...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK