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用戶組了。
