54

在 OS X 下构建 ARM 64 镜像

 4 years ago
source link: https://www.tuicool.com/articles/Abqqiy3
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.

Mac OS X 的 Docker 桌面版中加入了一个 buildx 的试验特性,启用之后,可以直接在 MAC 系统中构建 ARM64 和 ARM7 的镜像。启用方法很简单,打开 Docker 的配置窗口,进行如下配置:

ZJbEveM.png!web

打开这个功能之后,Docker 会重新启动一次,命令行中的 Docker 就多出一个 buildx 命令,可以用于构建异构镜像了。 进行构建之前,首先进行初始化:

$ docker buildx create --name builderx
$ docker buildx use mybuilder
$ docker buildx inspect --bootstrap
...
Endpoint:  unix:///var/run/docker.sock
Status:    running

接下来我们随便写一个 Dockerfile:

FROM ubuntu:18.10
CMD ["tini", "--", "sleep", "1d"]

在镜像库或者 Docker hub 上创建一个新仓库,就可以尝试 Build->Push 的操作了:

$ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t dustise/debug-container:v0.2 . --push
 => [internal] load .dockerignore                                                                                    0.0s
 => => transferring context: 2B                                                                                      0.0s
 => [internal] load build definition from Dockerfile                                                                 0.0s
 => => transferring dockerfile: 182B                                                                                 0.0s
 => [linux/arm64 internal] load metadata for docker.io/library/ubuntu:18.10                                          3.5s
 => [linux/arm/v7 internal] load metadata for docker.io/library/ubuntu:18.10                                         4.0s
 => [linux/amd64 internal] load metadata for docker.io/library/ubuntu:18.10                                          3.5s
 => [linux/arm64 1/2] FROM docker.io/library/ubuntu:18.10@sha256:7d657275047118bb77b052c4c0ae43e8a289ca2879ebfa78a7  0.0s

 ...
 => => pushing layers                                                                                                5.1s
 => => pushing manifest for docker.io/dustise/debug-container:v0.2

接下来可以打开你的 Harbor 或者 Docker Hub 查看一下,镜像库中是否已经加入了多平台的镜像内容:

JR3ayqM.png!web

buildx 还有 save 语法,可以直接将构建结果输出为压缩包,但是目前还没有提供完整支持。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK