懒猫微服进阶心得(七):懒猫的镜像仓库

忘机山人

发布于362天前
博客图片修整中,看不了可以先搜索公众号“忘机山人”看。
这几年国内访问 Dockerhub 总有类似的问题,所以很多情况都建议自建docker 仓库,比如 Habor,Nexus 或者。毕竟 GFW的花样我们想不到。

云厂商的 ECR。但是对于个人玩家或者爱好者来说这一套实在是太重太难以维护了,可能也就是这个原因,懒猫微服也提供了镜像仓库的和本地仓库的功能。

先说镜像仓库,就是从懒猫微服的服务器上先拉 Docker image,然后再推到自己的registry。这一步骤通常由出海链路比较好的机器来完成。

### 懒猫镜像同步功能

懒猫提供了便捷的镜像同步命令:
```bash
lzc-cli appstore copy-image cloudsmithy/lazycat-nav
```
执行之后就可以看到镜像仓库,registry.lazycat.cloud 这个地址。

![镜像同步界面截图](https://raw.githubusercontent.com/cloudsmithy/picgo-imh/master/image-20250606062550912.png)

**重要说明**:
这个地址只能在微服环境中使用,如果在其他地方使用会出现认证错误:
```bash
docker pull registry.lazycat.cloud/u04123229/cloudsmithy/lazycat-nav:854b14e73ab0726e
Error response from daemon: Head "https://registry.lazycat.cloud/v2/u04123229/cloudsmithy/lazycat-nav/manifests/854b14e73ab0726e": no basic auth credentials
```
其实就一个加了认证的registry,只是微服有凭证可以直接进。
![认证错误截图](https://raw.githubusercontent.com/cloudsmithy/picgo-imh/master/image-20250606081108772.png)

### 内置Docker Registry V2

懒猫微服内置了一个简化版的registry,完整使用流程如下:

```bash
# 构建x86架构镜像
docker build --platform linux/amd64 -t helloworld:latest .

# 获取当前微服名称
BOXNAME=$(lzc-cli box default)

# 为镜像打上仓库标签
docker tag helloworld:latest dev.$BOXNAME.heiyu.space/helloworld:latest

# 推送镜像到仓库
docker push dev.$BOXNAME.heiyu.space/helloworld:latest

# 从仓库拉取镜像
docker pull dev.$BOXNAME.heiyu.space/helloworld:latest
```

**实际操作演示**:

在M2芯片设备上的构建过程:
![M2构建截图](https://raw.githubusercontent.com/cloudsmithy/picgo-imh/master/image-20250606065450474.png)

在Orbstack上拉取验证(先删除本地镜像再拉取):
![镜像拉取验证](https://raw.githubusercontent.com/cloudsmithy/picgo-imh/master/image-20250606065226304.png)

通过API查看镜像列表:
![镜像列表API](https://raw.githubusercontent.com/cloudsmithy/picgo-imh/master/image-20250606075246823.png)

这个简单版本的docker registry v2,后面用来做跑CI的镜像仓库应该是够了。

### 插曲:

如果遇到这个问题,千万别信 AI 是 buildX 坏了,就是中文路径的问题。(AI查一小时。Google一分钟)

```bash
docker-container:multiarchERROR: failed to dial gRPC: rpc error: code = Internal desc = rpc error: code= Internal desc =header key"x-docker-expose-session-sharedkey" contains value with non-printable ASCII characters
```

评论

0

暂无评论

说点什么呢~
收藏
1
0
0