本文作者:丁辉
Docker部署Gitlab
部署开源版
例:本地 IP 为 192.168.1.10
部署Gitlab
启动容器
这里也可以通过
--hostname 192.168.1.10
指定 Clone 地址,Gitlab会通过读取本地主机名作为默认的 Clone 地址1
2
3
4
5
6
7
8
9
10
11docker run -itd \
--restart always \
-p 80:80 \
-p 222:22 \
-u root \
-v $PWD/data/log:/var/log/gitlab \
-v $PWD/data/opt:/var/opt/gitlab \
-v $PWD/data/etc:/etc/gitlab \
--privileged=true \
--name=gitlab \
gitlab/gitlab-ce:latest进入容器查看 root 初始密码
1
docker exec -it gitlab bash
1
cat /etc/gitlab/initial_root_password
访问 192.168.1.10:80
修改 SSH Clone 地址(进入容器内执行)
1
2cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak
vi /etc/gitlab/gitlab.rb写入如下内容
1
2
3external_url "http://192.168.1.10:80" #http对外clone地址
gitlab_rails["gitlab_ssh_host"] = "192.168.1.10" #ssh对外clone地址
gitlab_rails["gitlab_shell_ssh_port"] = 222 #ssh对外clone端口重启服务
1
gitlab-ctl reconfigure
安装Gitlab-runner
启动容器
1
2
3
4
5
6
7docker run -itd --name gitlab-runner \
--restart always \
--privileged=true \
-v $PWD/data/gitlab-runner-config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/local/bin/docker:/usr/bin/docker \
gitlab/gitlab-runner:latest创建 Runner 实例获取 Token
点击Admin Area(管理员设置) > 点击CI/CD > 点击Runners > 点击New project runner > 选择Linux > 填写一个Tags > 点击Create runner
进入容器
1
docker exec -it gitlab-runner bash
开始注册 Runner
1
gitlab-ci-multi-runner register
过程如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15Runtime platform arch=amd64 os=linux pid=106 revision=6e766faf version=16.4.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://192.168.1.10 #Gitlab地址
Enter the registration token:
******** #刚刚获取到的Token
Verifying runner... is valid runner=Te1gEas2d
Enter a name for the runner. This is stored only in the local config.toml file:
[f94c7a9b1272]: test #名称
Enter an executor: docker+machine, instance, kubernetes, docker-windows, shell, virtualbox, docker-autoscaler, custom, docker, parallels, ssh:
shell #输入一个执行器
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"开始测试
在测试仓库内创建
.gitlab-ci.yml
文件编写内容1
2
3
4
5
6
7
8stages:
- test
build-test:
stage: test
tags:
- test
script:
- echo "Hello world"查看结果
进入测试仓库 > 点击Build > 点击Pipelines > 查看到
passed
即为成功可点击进去查看
忘记密码
进入容器
1
docker exec -it gitlab /bin/bash
进⼊控制台(需要等待一段时间)
1
gitlab-rails console -e production
查询root⽤户
1
user=User.where(id:1).first
设置密码
1
user.password='password'
保存退出
1
2user.save!
exit
I'm so cute. Please give me money.
- 本文链接: https://blog.offends.cn/Kubernetes/Docker/Docs/Docker部署Gitlab.html
- 版权声明: 本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。