利用docker compose启动gitlab及runner
Posted Supper阿欣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用docker compose启动gitlab及runner相关的知识,希望对你有一定的参考价值。
添加docker compose配置文件
新建文件docker-compose.yml,输入如下内容:
gitlab: image: \'gitlab/gitlab-ce:latest\' container_name: \'gitlab\' restart: always hostname: \'gitlab.cjx.com\' environment: GITLAB_OMNIBUS_CONFIG: | external_url \'http://gitlab.cjx.com\' # Add any other gitlab.rb configuration here, each on its own line ports: - \'80:80\' - \'443:443\' - \'60000:22\' volumes: - \'/srv/gitlab/config:/etc/gitlab\' - \'/srv/gitlab/logs:/var/log/gitlab\' - \'/srv/gitlab/data:/var/opt/gitlab\' runner: image: \'gitlab/gitlab-runner:latest\' container_name: \'gitlab-runner\' restart: always links: - gitlab:gitlab.cjx.com volumes: - \'/srv/gitlab-runner/config:/etc/gitlab-runner\' - \'/var/run/docker.sock:/var/run/docker.sock\'
利用docker compose启动容器
docker-compose up -d
注册Runner,配置CI脚本
参照:http://www.cnblogs.com/windchen/p/6247137.html#configrunner
修正使用Docker方式执行时,无法正确link到gitlab的问题
虽然在gitlab-runner这个容器里面,有link到gitlab,但是build如果是选择的docker,执行时会再启动一个子容器,子容器无法识别自定义host:gitlab.cjx.com,会报 port 80 : connection refused错误,解决办法是在runnner的配置文件添加links参数
sudo vi /srv/gitlab-runner/config/config.toml
在[runners.docker]节点下面,添加红色字部分
executor = "docker" [runners.docker] links = ["gitlab:gitlab.cjx.com"] tls_verify = false image = "ruby:2.1" privileged = false disable_cache = false volumes = ["/cache"]
添加好之后,重启runner,就可以正常访问到gitlab获取code了。
docker exec -it gitlab-runner gitlab-runner restart
以上是关于利用docker compose启动gitlab及runner的主要内容,如果未能解决你的问题,请参考以下文章