gitlab cicd (三)系列之安装git-runner docker安装方式

本编博客是继gitlab cicd (二)系列之安装git-runner rpm安装方式之后另一种安装gitlab-runner的安装方式—容器安装方式

1.安装docker
请参考安装docker 17.03.2.ce教程

docker版本

[root@gitlab-runner-64 ~]# docker version 
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:48:22 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:19:08 2018
  OS/Arch:          linux/amd64
  Experimental:     false

启动gitlab-runner

 docker run -d --name gitlab-runner --restart always \
   -v /srv/gitlab-runner/config:/etc/gitlab-runner \
   -v /var/run/docker.sock:/var/run/docker.sock \
   gitlab/gitlab-runner:latest

或者可以使用第三方存储valume的启动方式

 docker run -d --name gitlab-runner-config \
     -v /etc/gitlab-runner \
     busybox:latest \
     /bin/true

docker run -d --name gitlab-runner --restart always \
     -v /var/run/docker.sock:/var/run/docker.sock \
     --volumes-from gitlab-runner-config \
     gitlab/gitlab-runner:latest

向gitlab服务注册gitlab-runner

gitlab token 获取如下图
gitlab cicd (三)系列之安装git-runner docker安装方式_第1张图片

执行命令,具体注册方式参考下图

 docker run --rm -t -i -v /srv/gitlab-runner/config:/etc/gitlab-runner --name gitlab-runner gitlab/gitlab-runner register

gitlab cicd (三)系列之安装git-runner docker安装方式_第2张图片

执行完成之后,会有以下文件生成/srv/gitlab-runner/config

[root@gitlab-runner-64 ~]# cat /srv/gitlab-runner/config/config.toml 
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker-runner"
  url = "http://10.39.47.63/"
  token = "d4027a7f23390e8e2519d93564c0a7"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "golang:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock","/cache"]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

启动gitlab-runner

gitlab cicd (三)系列之安装git-runner docker安装方式_第3张图片

[root@gitlab-runner-64 ~]# docker ps 
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS               NAMES
d77ff46d00d2        gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   51 seconds ago      Up 51 seconds                           gitlab-runner

查看是否已经注册完成
gitlab cicd (三)系列之安装git-runner docker安装方式_第4张图片

执行效果
gitlab cicd (三)系列之安装git-runner docker安装方式_第5张图片
end

参考:

Run GitLab Runner in a container
Registering Runners

你可能感兴趣的:(cicd)