della0887 发表于 2017-12-7 07:40:49

Docker in Docker版本Gitlab CI Runner配置

  1.构建新的gitlab-runner image,使用如下Dockerfile(ubuntu版本):



FROM gitlab/gitlab-runner
RUN apt-get update -y
RUN apt-get install -y libltdl-dev && \
rm -rf /var/lib/apt/lists/*



docker build -t gitlab-ci-runner .
  2.改变宿主机(centos) /var/run/docker.sock的用户组为root:root



sudo chown root:root /var/run/docker.sock
  3.启动gitlab-ci-runner



docker run -d --name gitlab-runner --restart always   -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker-v /srv/gitlab-runner/config:/etc/gitlab-runner   gitlab-ci-runner
  4.将新启动的容器中的gitlab-runner用户加入root组以可以调用docker:



docker exec -it gitlab-runner usermod -aG root gitlab-runner
  5.注册新的gitlabrunner:



docker exec -it gitlab-runner gitlab-runner register
  6.接下来按照http://www.cnblogs.com/flasheryu/p/6183573.html中流程注册即可,executor选择shell!
  注意:
  1. centos下需要安装docker-engine而不是docker:



yum -y install docker-engine
  否则会报错:
  /usr/bin/docker: 2: .: Can't open /etc/sysconfig/docker
  2.每次重启docker service的时候都需要重置docker.sock的所属组。。



service docker restart
chown root:root /var/run/docker.sock
  使用如下方法可以解决这个问题:



vi /usr/lib/systemd/system/docker.service
  更改以下这行,添加-G root,使其以root用户启动:



ExecStart=/usr/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 -G root
  此时/var/run/docker.sock即是root:root用户组了。
页: [1]
查看完整版本: Docker in Docker版本Gitlab CI Runner配置