gitlab启用自带的docker registry

gitlab启用自带的docker registry

gitlab安装后默认不开启自带的docker registry。 需要修改/etc/gitlab/gitlab.rb文件,修改以下配置


registry_external_url ‘http://X.X.X.X:4567’
注意,请不要使用5000端口,因为被gitlab所带的nginx默认占用了。配置前查一遍自己的端口占用情况

这里配置不带ssl证书认证的docker registry。修改后执行以下命令重启

sudo gitlab-ctl stop
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start

安装后随便找个项目都能看到packages-container registry,还能看到各种提示信息,比如登录 docker login X.X.X.X:1234

这个内置的registry的用户名和密码账户与gitlab一致,可以和gitlab-runner 配合,在.gitlab-ci.yaml里使用

我们随便找个镜像nginx来演示推送过程

先把nginx拖下来

[[email protected] ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
000eee12ec04: Pull complete 
eb22865337de: Pull complete 
bee5d581ef8b: Pull complete 
Digest: sha256:50cf965a6e08ec5784009d0fccb380fc479826b6e0e65684d9879170a9df8566
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

然后我们重新打tag,这个非常重要,要推送到哪个仓库,就得把对应的地址写在tag里面,比如我的仓库是 10.196.12.251:4567/root/cicd-toolset 这个地址你刚把registry创建出来上面有,找不到没关系,就是你的项目地址,只不过前面要把仓库的端口号写上去。

我为了方便打了3个tag v1 v2 v3

[[email protected] ~]# docker tag nginx:latest 10.196.12.247:4567/root/cicd-toolset/nginx:v1
[[email protected] ~]# docker tag nginx:latest 10.196.12.247:4567/root/cicd-toolset/nginx:v2
[[email protected] ~]# docker tag nginx:latest 10.196.12.247:4567/root/cicd-toolset/nginx:v3
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker stable 8e347affc72a 11 days ago 222MB
10.196.12.247:4567/root/cicd-toolset/nginx v1 231d40e811cd 4 weeks ago 126MB
10.196.12.247:4567/root/cicd-toolset/nginx v2 231d40e811cd 4 weeks ago 126MB
10.196.12.247:4567/root/cicd-toolset/nginx v3 231d40e811cd 4 weeks ago 126MB
nginx latest 231d40e811cd 4 weeks ago 126MB
最后一步,推送,后两个报错请忽略,因为本来就是一个镜像
[[email protected] ~]# docker push 10.196.12.247:4567/root/cicd-toolset/nginx:v1
The push refers to repository [10.196.12.247:4567/root/cicd-toolset/nginx]
4fc1aa8003a3: Pushed 
5fb987d2e54d: Pushed 
831c5620387f: Pushed 
v1: digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a size: 948
[[email protected] ~]# docker push 10.196.12.247:4567/root/cicd-toolset/nginx:v2
The push refers to repository [10.196.12.247:4567/root/cicd-toolset/nginx]
4fc1aa8003a3: Layer already exists 
5fb987d2e54d: Layer already exists 
831c5620387f: Layer already exists 
v2: digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a size: 948
[[email protected] ~]# docker push 10.196.12.247:4567/root/cicd-toolset/nginx:v3
The push refers to repository [10.196.12.247:4567/root/cicd-toolset/nginx]
4fc1aa8003a3: Layer already exists 
5fb987d2e54d: Layer already exists 
831c5620387f: Layer already exists 
v3: digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a size: 948

去仓库确认一下,镜像都上来了

此条目发表在Docker, gitlab分类目录,贴了, 标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注