Deploy Gitlab-Runner through Docker

Mount the Gitlab config file for persistence

docker run -d --name gitlab-runner --privileged=true --restart always -v /opt/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock -v /root/.docker/:/root/.docker/ gitlab/gitlab-runner:latest 
Copy the code

Register the address and token related information of gitLab for the runner by entering the container

`[root@cloud1 /opt/gitlab-runner/config]# docker exec -it gitlab-runner gitlab-runner register`
Runtime platform                                    arch=amd64 os=linux pid=253 revision=c1edb478 version=14.01.
Running in system-mode.                            
                                                   
Enter the GitLab instance URL (for example, https://gitlab.com/):


Copy the code

By checking gitlab at this time, we can see that the Gitlab-Runner we registered has appeared

However, this runner is actually not available at this time, because when we use it, it involves pulling some mirrors of the private warehouse, so it does not have permission at this time, so we need to configure it through Gitlab-RunnervolumesParameter to mount information about its local login

`[root@cloud1 /opt/gitlab-runner/config]# cat config.toml `
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker-01"
  url = "xxx"
  token = "xxx"
  executor = "docker"[runners.custom_build_dir] [runners.cache] [runners.cache.s3] [runners.cache.gcs] [runners.cache.azure] [runners.docker]  tls_verify =false
    image = Ruby: "2.6"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock"."/root/.docker/:/root/.docker/"]
    shm_size = 0
Copy the code

Simple optimization

  1. Modify the runner configuration file, modify the runner start container rules, when there is a local image will not be repeated pull, saving time
pull_policy = "if-not-present"
Copy the code

After that, restart the Gitlab-Runner

# Restart`[root@cloud1 /opt/gitlab-runner/config]# docker exec -it gitlab-runner gitlab-runner restart `
Runtime platform  arch=amd64 os=linux pid=112 revision=c1edb478 version=14.01.
Copy the code

The end! At this point, The Gitlabrunner deployed by Docker can be used normally