惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
美团技术团队
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
有赞技术团队
有赞技术团队
GbyAI
GbyAI
宝玉的分享
宝玉的分享
腾讯CDC
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
月光博客
月光博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog

博客园 - 川川籽

GO面试题:new 和 map 的区别 minikube dashboard ImagePullBackOff 失败问题的解决方法 hashicorp/raft模块实现的raft集群存在节点跨集群身份冲突问题 macos 13安装openvpn - 川川籽 [转发] Go pprof内存指标含义备忘录 自己搭建一个https的dns,让不同的浏览器使用不同的DNS,使用相同的域名访问到不同的主机上 Linux C 获取本机IPV4和IPV6地址列表 Mac M1 安装python3.6.x golang map 和 interface 的一些记录 MacOS M1 安装python3.5 使用php的openssl_encrypt和python的pycrypt进行跨语言的对称加密和解密问题 golang random string 【转载】coroutine 与 goroutine 区别 python简单的time ticker 'invalid flag in #cgo LDFLAGS: -w' 问题解决 记录一次python的mysqlclient依赖库报错问题 airflow当触发具有多层subDAG的任务的时候,出现[Duplicate entry ‘xxxx’ for key dag_id]的错误的问题处理 Python3并发写文件 python hash 每次调用结果不一样
记一次docker buildx build 推送到本地私有仓库出现 connecti...
川川籽 · 2023-12-08 · via 博客园 - 川川籽

想在本地编译多个架构的基础镜像,这样后续有其他业务使用的时候,不必从头开始编译。
使用传统的 docker build -t ImageName:tag 方式,只能编译和主机相同架构的镜像。
docker buildx build 不支持将编译好的镜像放置在本地docker中,只能以文件的形式放在本地。因此需要在本地搭建一个私有仓库,并将编译好的多架构的基础镜像推送到私有仓库进行存储。
搭建私有仓库比较简单,使用一条命令即可搭建完毕:

docker run -d -p 5000:5000 -v /data/docker_registry:/var/lib/registry --restart=always --name registry registry

私有仓库搭建好了,先写一个简单的镜像例子来测试下:

[root@yzc ~]# mkdir alpine && cd alpine
[root@yzc alpine]# cat Dockerfile
# syntax=docker/dockerfile:1
FROM alpine:3.16
RUN apk add curl

然而在buildx推送到本地确报了这个明明奇妙的问题:

[root@yzc alpine]# docker buildx build --platform linux/amd64,linux/arm64 -t localhost:5000/myalpine:latest -o type=registry --allow network.host .
 => [internal] booting buildkit
 => => pulling image moby/buildkit:buildx-stable-1
 ... 省略一堆无关紧要的日志...
 => [linux/arm64 2/2] RUN apk add curl
 => [linux/amd64 2/2] RUN apk add curl
 => ERROR exporting to image
 => => exporting layers
 => => pushing layers
------
 > exporting to image:
------
ERROR: failed to solve: failed to push localhost:5000/myalpine:latest: failed to do request: Head "http://localhost:5000/v2/myalpine/blobs/sha256:56c7f5339f91bf07cf643df98dbc5386d3026f44072ca00913e1512a15649fb5": dial tcp 127.0.0.1:5000: connect: connection refused

看起来是docker buildx创建的实例的权限问题。

看了下文档,有人说要按照这个搞个配置文件https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md, 于是按照这个搞了一个,没想到莫名其妙的问题太多了,于是删除了大量配置,只留了几条:

# cat ~/.config/buildkit/buildkitd.toml
debug = true
# root is where all buildkit state is stored.
root = "/var/lib/buildkit"
# insecure-entitlements allows insecure entitlements, disabled by default.
insecure-entitlements = [ "network.host", "security.insecure" ]

[log]
  # log formatter: json or text
  format = "text"

[dns]
  nameservers=["1.1.1.1","8.8.8.8"]
  options=["edns0"]
  #searchDomains=["example.com"]

# optionally mirror configuration can be done by defining it as a registry.
[registry."localhost:5000"]
  http = true
  insecure = true

删掉现有docker buildx的实例,重新创建:

docker buildx rm default
docker buildx create --name muilt_buildx --platform 'linux/arm64,linux/amd64,linux/amd64/v2,linux/arm/v7,linux/arm/v6,linux/amd64/v3,linux/386' --config ~/.config/buildkit/buildkitd.toml --use

还是不行,一样的错误

看了下docker buildx create的说明,百度了下相关选项说明,然后删了现有实例重新创建就好了。

Options:
      --append                   Append a node to builder instead of changing it
      --bootstrap                Boot builder after creation
      --buildkitd-flags string   Flags for buildkitd daemon
      --config string            BuildKit config file
      --driver string            Driver to use (available: "docker-container", "kubernetes", "remote")
      --driver-opt stringArray   Options for the driver
      --leave                    Remove a node from builder instead of changing it
      --name string              Builder instance name
      --node string              Create/modify node with given name
      --platform stringArray     Fixed platforms for current node
      --use                      Set the current builder instance
docker buildx rm muilt_buildx
docker buildx create --name muilt_buildx --platform 'linux/arm64,linux/amd64,linux/amd64/v2,linux/arm/v7,linux/arm/v6,linux/amd64/v3,linux/386' --driver-opt=network=host --use

再次执行上面的哪个buildx build命令即可,查看本地仓库列表:

curl 127.0.0.1:5000/v2/_catalog
{"repositories":["myalpine"]}

# 也能正常pull
# docker pull localhost:5000/myalpine:latest
latest: Pulling from myalpine
070eb51debd9: Pull complete
5761c5c4cc74: Pull complete
Digest: sha256:3b134a4faf8cb7e57efc549804e438270349ed7bfe4525edd42288d47d23e069
Status: Downloaded newer image for localhost:5000/myalpine:latest
localhost:5000/myalpine:latest

OK