使用Docker搭建GitLab、Nexus、Registry
最佳建议,一个服务器部署一个相应服务,如果服务器够强大,就可忽视忽视。
GitLab的部署
- 下载镜像
GitLab社区中文版镜像地址
$ docker pull twang2218/gitlab-ce-zh
注:下载镜像这步操作可省略,直接执行 docker-compose up 命令,本地没有相应镜像的话docker会自动远程搜索下载docker-compose.yml配置的镜像。
- 创建docker-compose.yml
/usr/local/docker/gitlab/docker-compose.yml 写入以下内容,没有相应文件或文件夹则新建
version: '3.1'
services:
web:
image: 'twang2218/gitlab-ce-zh'
restart: always
hostname: '10.0.0.128'
container_name: gitlab
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
enternal_url 'http://10.0.0.128:8080'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
unicorn['port'] = 8888
nginx['listen_port'] = 80
ports:
- '80:80'
- '8443:443'
- '2222:22'
volumes:
- /usr/local/docker/gitlab/config:/etc/gitlab
- /usr/local/docker/gitlab/data:/var/opt/gitlab
- /usr/local/docker/gitlab/logs:/var/log/gitlab
- 运行docker-compose
$ cd /usr/local/docker/gitlab/
$ docker-compose up -d
-d 是后台启动参数,去掉可以查看启动实时情况,或者使用 docker logs [container_name] 查看启动日志
Nexus的部署
- 下载镜像
Nexus3镜像地址
$ docker pull sonatype/nexus3
- 创建docker-compose.yml
/usr/local/docker/nexus/docker-compose.yml 写入以下内容,没有相应文件或文件夹则新建
version: '3.1'
services:
nexus:
restart: always
image: sonatype/nexus3
container_name: nexus
ports:
- 8081:8081
volumes:
- /usr/local/docker/nexus/data:/nexus-data
- 运行docker-compose
$ cd /usr/local/docker/nexus/
$ docker-compose up -d
运行可能会遇到权限问题导致无法创建一些文件,给/usr/local/docker/nexus/data目录添加权限即可,如:chmod 777 data/
项目中Nexus的使用: https://blog.csdn.net/qq_40839030/article/details/101067989
Registry的部署
- 下载镜像
Registry镜像地址
$ docker pull registry
- 创建docker-compose.yml
/usr/local/docker/nexus/docker-compose.yml 写入以下内容,没有相应文件或文件夹则新建
version: '3.1'
services:
registry:
image: registry
restart: always
container_name: registry
ports:
- 5000:5000
volumes:
- /usr/local/docker/registry/data:/var/lib/registry
- 运行docker-compose
$ cd /usr/local/docker/registry/
$ docker-compose up -d
可点击以下链接,查看API,然后测试效果
Registry Restful API
4. 客户端配置镜像私服
/etc/docker/daemon.json文件添加"insecure-registries":“ip:port”。
结果如下:
{
"registry-mirrors": [
"https://registry.docker-cn.com"
],
"insecure-registries": [
"192.168.1.128:5000"
]
}
然后重新启动服务:
$ sudo systemctl restart docker
用 docker tag 命令标记镜像,然后 docker push 命令推送到镜像服务器,如:
$ docker tag tomcat 192.168.1.128:5000/tomcat
$ docker push 192.168.1.128:5000/tomcat
- 配置WebUI客户端
修改docker-compose.yml(修改前使用在文件目录下使用docker-compose down关闭服务),添加服务frontend,结果如下
version: '3.1'
services:
registry:
image: registry
restart: always
container_name: registry
ports:
- 5000:5000
volumes:
- /usr/local/docker/registry/data:/var/lib/registry
frontend:
image: konradkleine/docker-registry-frontend:v2
restart: always
ports:
- 8080:80
volumes:
- ./certs/frontend.crt:/etc/apache2/server.crt:ro
- ./certs/frontend.key:/etc/apache2/server.key:ro
environment:
- ENV_DOCKER_REGISTRY_HOST=192.168.1.128
- ENV_DOCKER_REGISTRY_PORT=5000
docker-compose up -d再启动,http://192.168.81.128:8080,直接访问WebUI,查看效果