您现在的位置是:首页 >技术杂谈 >Docker Gitlab Container Registry配置网站首页技术杂谈
Docker Gitlab Container Registry配置
前言
找了很多资料包括官网1都没有发现比较清楚的配置registry的方法,自己摸索了半天发现其实通过简单设置就能够配置好Container Registry
。
之所以在题目中说明http访问是由于之前在配置安装本地gitlab时也是配置的http访问原文为《gitlab使用docker简单快速部署》,在此基础上如何简单配置好registry用来保存ci打包好的镜像便是这篇文章主要内容
一、Registry是什么
Docker Registry是一个用于存储和分发Docker镜像的服务器应用程序。它可以让开发人员轻松分享和管理他们的Docker镜像,并让其他人轻松访问和下载这些镜像。Docker Registry可以运行在本地网络或公共云服务上,并提供了多种可选择的存储后端,如Amazon S3、Google Cloud Storage和Azure Blob Storage等。同时,Docker Registry还提供了认证、授权和安全方面的功能,使得开发人员可以更加安全地管理和共享他们的镜像。
Docker提供了Docker Registry工具,可以用于构建私有镜像仓库,gitlab
在使用docker配置安装时其实也能简单同时搭建好一个registry用来保存你在编译过程中打包的镜像。
简单的来说就是一个镜像保存服务器,并且gitlab配置的这个服务器还能使用本地gitlab用户名和密码登陆,CI在打包时也能很方便的将镜像推送到镜像服务器做保存。
二、步骤
配置gitlab.rb文件
你所需要修改的只有如下几行,
# 注意这里是http,地址写你的本地路由地址,前边加registry
registry_external_url 'http://registry.gitlab.example.com'
gitlab_rails['registry_enabled'] = true
# 如前
gitlab_rails['registry_host'] = "registry.gitlab.example.com"
# 这里写你想保存的路径,注意这里写的是容器内的路径
gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"
较完整这一块的配置如下:
...
# gitlab_rails['redis_yml_override'] = nil
################################################################################
## Container Registry settings
##! Docs: https://docs.gitlab.com/ee/administration/packages/container_registry.html
################################################################################
registry_external_url 'http://registry.gitlab.example.com'
### Settings used by GitLab application
gitlab_rails['registry_enabled'] = true
gitlab_rails['registry_host'] = "registry.gitlab.example.com"
#gitlab_rails['registry_port'] = "5050"
gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"
# Notification secret, it's used to authenticate notification requests to GitLab application
# You only need to change this when you use external Registry service, otherwise
# it will be taken directly from notification settings of your Registry
# gitlab_rails['registry_notification_secret'] = nil
###! **Do not change the following 3 settings unless you know what you are
###! doing**
# gitlab_rails['registry_api_url'] = "http://192.168.1.90:5005"
# gitlab_rails['registry_key_path'] = "/var/opt/gitlab/gitlab-rails/certificate.key"
# gitlab_rails['registry_issuer'] = "omnibus-gitlab-issuer"
### Settings used by Registry application
#registry['enable'] = true
# registry['username'] = "registry"
# registry['group'] = "registry"
# registry['uid'] = nil
# registry['gid'] = nil
...
修改docker-compose.yaml文档
代码如下:
# docker-compose.yml
services:
web:
image: 'gitlab/gitlab-ee:15.11.2-ee.0'
restart: always
hostname: 'gitlab.example.com'
container_name: gitlab
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com'
# Add any other gitlab.rb configuration here, each on its own line
# NOTICE! here change to 'http' instead of 'https'
ports:
- '80:80'
- '443:443'
- '22:22'
- '5000:5000'
# 这里增加了5000端口
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
version: '3.6'
使用docker-compose restart
即可重启容器完成配置。
成功运行后结果如下所示:
验证推送镜像
$ docker pull busybox
$ docker login registry.gitlab.***.com
Username: *
Password:
WARNING! Your password will be stored unencrypted in /home/dev/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker tag busybox:latest registry.gitlab.***.com/common/fc_robot_resources:latest
$ docker push registry.gitlab.***.com/common/fc_robot_resources:latest
The push refers to repository [registry.gitlab.***.com/common/fc_robot_resources]
9547b4c33213: Pushed
latest: digest: sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43 size: 528
即可成功推送,这时gitlab上也可以看到对应的打包镜像。
注意:
如果docker login
报错Error response from daemon: Get "https://registry.gitlab.***.com/v2/": dial tcp 192.168.1.1:443: connect: connection refused
可以参考如下文章解决《docker使用http服务及国内镜像加速》
总结
以上就是所有的内容,本文通过简单的流程和图示按步实现了Gitlab Container Registry的配置。