在本章节中,将为您演示如何在docker上运行gitlab
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务,想必各位开发者在日常代码开发需要将代码同步至Github或者Gitee仓库中,也有可能由于某些网络和审计原因,我们不能将代码托管到公共仓库,那么我们可以构建自己的私有代码托管仓库---gitlab
本次使用的是极狐GitLab Docker 镜像,是极狐GitLab 的整体镜像,在单个容器中运行所有必要的服务
- [root@base ~]# docker pull registry.gitlab.cn/omnibus/gitlab-jh:latest
- Trying to pull repository registry.gitlab.cn/omnibus/gitlab-jh ...
- latest: Pulling from registry.gitlab.cn/omnibus/gitlab-jh
- 3b65ec22a9e9: Pull complete
- 9ce3f6b2507d: Pull complete
- ac19a78281d5: Pull complete
- bb3c3f1c8644: Pull complete
- 68ca2a4567a0: Pull complete
- bc72d87c5eba: Pull complete
- 39c50a8c026b: Pull complete
- 8a5f2ec13e24: Pull complete
- Digest: sha256:f21efbd86aadfe2e353799d56811a09a507c7fcf40cd2999fb16237b72469128
- Status: Downloaded newer image for registry.gitlab.cn/omnibus/gitlab-jh:latest
- [root@base ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mysql latest d39235e17905 5 days ago 571 MB
- <none> <none> 75279e2d58b5 5 days ago 101 MB
- nginx_alb latest 4e28f6e4fc6a 6 days ago 390 MB
- ssh-server latest 4e28f6e4fc6a 6 days ago 390 MB
- registry.gitlab.cn/omnibus/gitlab-jh latest e1136770c69f 7 days ago 2.91 GB
- docker.io/registry latest 3a0f7b0a13ef 3 weeks ago 24.1 MB
- docker.io/ubuntu <none> df5de72bdb3b 4 weeks ago 77.8 MB
- docker.io/nginx latest 605c77e624dd 8 months ago 141 MB
- docker.io/ubuntu latest ba6acccedd29 10 months ago 72.8 MB
- docker.io/centos 7 eeb6ee3f44bd 11 months ago 204 MB
-
- 复制代码
其实就是设置待会gitlab容器需要挂载卷的位置,当然这些需要提前在宿主机创建
- [root@base ~]# mkdir /opt/gitlab
- [root@base ~]# ls -l /opt/
- total 0
- drwxr-xr-x. 2 root root 6 Aug 31 18:31 gitlab
- [root@base ~]# chmod a+w /opt/gitlab/
- [root@base ~]# ls -l /opt/
- total 0
- drwxrwxrwx. 2 root root 6 Aug 31 18:31 gitlab
- 复制代码
- [root@base ~]# export GITLAB_HOME=/opt/gitlab
- # 查看
- [root@base ~]# export |grep GITLAB_HOME
- declare -x GITLAB_HOME="/opt/gitlab"
- 复制代码
原本官方使用的是 22:22端口映射,但是因为宿主机已经在使用22的端口,那么就修改一下映射为10022
- [root@base ~]# sudo docker run --detach \
- > --publish 443:443 --publish 80:80 --publish 10022:22 \
- > --name gitlab \
- > --restart always \
- > --volume $GITLAB_HOME/config:/etc/gitlab \
- > --volume $GITLAB_HOME/logs:/var/log/gitlab \
- > --volume $GITLAB_HOME/data:/var/opt/gitlab \
- > --shm-size 256m \
- > registry.gitlab.cn/omnibus/gitlab-jh:latest
- b848d1c24944b551525007c4f2749e08ae327b6d8ad9934776c0c038348a517f
- [root@base ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- b848d1c24944 registry.gitlab.cn/omnibus/gitlab-jh:latest "/assets/wrapper" 9 seconds ago Up 5 seconds (health: starting) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:10022->22/tcp gitlab
- 7dda8b117154 registry "/entrypoint.sh /e..." 6 days ago Up 3 hours 0.0.0.0:5000->5000/tcp registry
- 复制代码
进入容器再操作
- [root@base ~]# docker exec -it gitlab bash
- root@0fd6622feef2:/#
- 复制代码
- root@0fd6622feef2:/# vi /etc/gitlab/gitlab.rb
- # 修改external_url 'GENERATED_EXTERNAL_URL'
- external_url 'http://192.168.200.201'
-
- # 设置ssh链接,使用宿主机的外部端口
- gitlab_rails['gitlab_ssh_host'] = '192.168.200.201'
- gitlab_rails['gitlab_shell_ssh_port'] = 10022
-
- 按下ESC
- :wq #保存退出
- 复制代码
- root@0fd6622feef2:/# vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
- # 13行 host修改为 宿主机IP地址
- host: 192.168.200.201
- ssh_host: 192.168.200.201
- 按下ESC
- :wq #保存退出
- 复制代码
- # 如果timeout(超时),那么多重启几次
- root@0fd6622feef2:/# gitlab-ctl restart
- ok: run: alertmanager: (pid 2390) 1s
- ok: run: gitaly: (pid 2398) 0s
- ok: run: gitlab-exporter: (pid 2412) 0s
- ok: run: gitlab-kas: (pid 2414) 0s
- ok: run: gitlab-workhorse: (pid 2422) 0s
- ok: run: logrotate: (pid 2433) 0s
- ok: run: nginx: (pid 2439) 1s
- ok: run: postgres-exporter: (pid 2445) 0s
- ok: run: postgresql: (pid 2453) 1s
- ok: run: prometheus: (pid 2462) 0s
- ok: run: puma: (pid 2472) 1s
- ok: run: redis: (pid 2477) 0s
- ok: run: redis-exporter: (pid 2483) 0s
- ok: run: sidekiq: (pid 2571) 0s
- ok: run: sshd: (pid 2577) 1s
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走
这些资料,对于想进阶【自动化测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….