Docker-compose安装gitlab-ce带gitlab-runner实现CI/CD

在网上看了很多docker-compose联合安装gitlab和gitlab-runner的文章,都多少有点欠缺,也许是因为版本更新了。自己爬了两天的坑,现在把docker安装gitlab-ce和runner的坑填上。

新建一个目录gitlab,新建一个文件docker-compose.yml

docker-compose.yml 配置文件

version: '2'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    restart: unless-stopped
    container_name: 'gitlab'
    hostname: 'gitlab'
    ports:
      - '81:80'
      - '22:22'
    volumes:
       - /data/docker/gitlab/config:/etc/gitlab
       - /data/docker/gitlab/data:/var/opt/gitlab
       - /data/docker/gitlab/logs:/var/log/gitlab

  gitlab-runner:
    image: 'gitlab/gitlab-runner:latest'
    restart: unless-stopped
    container_name: 'gitlab-runner'
    depends_on:
      - gitlab
    privileged: true
    volumes:
      - ./config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock

运行docker-compose:

docker-compose up

这时gitlab已经可以访问了,但是gitlab-runner疯狂报错,说什么config文件不存在,没事,让他报

注册docker-runner

docker exec -it gitlab-runner gitlab-runner register

在gitlab项目下的setting中找到CI/CD选项,输入urltoken,runner选择docker即可。

注册完后上面的报错就没了,大功告成!

posted @ 2020-12-23 10:53  devilyouwei  阅读(1225)  评论(0编辑  收藏  举报