使用 docker 安装 gitlab 并且配置 runner
2018-06-24 本文已影响0人
w也不知道
一、修改 docker 镜像源为国内源
# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://lvpmz2sk.mirror.aliyuncs.com"]
}
systemctl reload docker #修改完成后重新载入docker服务
二、使用 docker-compose 管理 gitlab 和 gitlab-runner 容器镜像
# vi docker-compose.yml
version: '2'
services:
gitlab:
image: gitlab/gitlab-ce:11.0.0-ce.0
restart: always
hostname: gitlab
container_name: gitlab
ports:
- 80:80
volumes:
- /etc/localtime:/etc/localtime
- ./conf:/etc/gitlab
- ./data/logs:/var/log/gitlab
- ./data/data:/var/opt/gitlab
gitlab-runner:
image: gitlab/gitlab-runner
restart: always
hostname: gitlab-runner
container_name: gitlab-runner
extra_hosts:
- git.imlcs.top:192.168.88.167
depends_on:
- gitlab
volumes:
- /etc/localtime:/etc/localtime
- ./runner:/etc/gitlab-runner
目录结构
安装过程中遇到的问题:
/opt/gitlab/embedded/bin/runsvdir-start: line 24: ulimit: pending signals: cannot modify limit: Operation not permitted
/opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system Configuring GitLab package... Configuring GitLab...
解决方法:
chmod 2770 data/data/git-data/repositories
docker-compose down
docker-compose up -d(初次创建时 gitlab 启动很慢,估计需要十几分钟左右)
三、gitlab 成功启动后连接到 gitlab-runner 配置 gitlab 的 gitlab-runner
docker-compose exec gitlab-runner sh # 连接进入 gitlab-runner 容器
gitlab-runner register # 进入容器后执行的命令
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://git.imlcs.top # gitlab 的访问路径
Please enter the gitlab-ci token for this runner:
JLP2Rk2qcUZEfs_WLrTv # 注册令牌,在 gitlab 中获取
Please enter the gitlab-ci description for this runner:
[gitlab-runner]: test_runner # runner 的名字
Please enter the gitlab-ci tags for this runner (comma separated):
test # runner 的 tag
Registering runner... succeeded runner=JLP2Rk2q
Please enter the executor: docker-ssh, parallels, docker+machine, docker-ssh+machine, docker, shell, ssh, virtualbox, kubernetes:
docker # 使用 docker 作为输出模式
Please enter the default Docker image (e.g. ruby:2.1):
alpine:latest # 使用的基础镜像
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
############################# 注册成功后会显示以上信息,然后执行下面的命令进行启动 ###################################
gitlab-runner start # 启动该 runner
使用 root 用户登录 gitlab 后获取令牌
注册成功后会显示的runner的信息