使用 Gitlab 的镜像仓库

Kubernetes 已经是事实标准,很多应用都会以容器镜像作为交付物。Gitlab 自然是不甘人后,也集成了容器镜像仓库的功能。

在使用 Helm 安装 Gitlab 时,设置 registry.enabled=true 即可启用镜像仓库功能。该功能启用之后,就可以用 Docker 客户端进行操作了。

我们使用项目 root/sample 作为示例:

# 登录
$ docker login registry.microservice.xyz

Username: root
Password:
Login Succeeded

$ docker tag alpine:latest registry.microservice.xyz/root/sample/alpine:latest

# 推送镜像
$ docker push registry.microservice.xyz/root/sample/alpine:latest
The push refers to repository [registry.microservice.xyz/root/sample/alpine]
7bff100f35cb: Pushed
latest: digest: sha256:3d2e482b82608d153a374df3357c0291589a61cc194ec4a9ca2381073a17f58e size: 528

镜像推送成功后,浏览项目的 registry 菜单,例如 https://gitlab.microservice.xyz/root/sample/container_registry,就会看到新推送的镜像:

List images

关于镜像的路径,该页面上的说法是:允许存在三个层次,例如下列命名都是合法的:

registry.microservice.xyz/root/sample:tag
registry.microservice.xyz/root/sample/optional-image-name:tag
registry.microservice.xyz/root/sample/optional-name/optional-image-name:tag

其它路径的推送会被拒绝,例如:

$ docker tag alpine:latest registry.microservice.xyz/root/alpine:latest
$ docker push  registry.microservice.xyz/root/alpine:latest
The push refers to repository [registry.microservice.xyz/root/alpine]
7bff100f35cb: Preparing
denied: requested access to the resource is denied
上一页