如何部署docker excutor gitlab runner

前提:安装docker

  apt-get install docker-ce

设置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

注册 runner

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

* Enter your GitLab instance URL:

* Enter the token you obtained to register the Runner:

* Enter a description for the Runner, you can change this later in GitLab’s UI:

* Enter the tags associated with the Runner, you can change this later in GitLab’s UI:

* Enter the Runner executor: docker

* If you chose Docker as your executor, you’ll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml: alpine:latest

坑一:

run job时报错  docker executor Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解决方法:编辑  /srv/gitlab-runner/config/config.toml  添加

volumes = ["/var/run/docker.sock:/var/run/docker.sock"]

坑二:

 有些问题会使用cache保存临时文件,最终config.toml 文件最好如下:

concurrent = 20

check_interval = 0

[session_server]

  session_timeout = 1800

[[runners]]

  name = "runner-name"

  url = "https://xxxxx/"

  token = "xxxxxxx"

  executor = "docker"

  limit = 0

  [runners.docker]

    tls_verify = false

    image = "alpine:latest"

    privileged = false

    disable_entrypoint_overwrite = false

    oom_kill_disable = false

    disable_cache = false

    cache_dir="/srv/gitlab-runner/cache"

    volumes = ["/var/run/docker.sock:/var/run/docker.sock","/srv/gitlab-runner/cache:/cache"]

    shm_size = 0

  [runners.cache]

    [runners.cache.s3]

    [runners.cache.gcs]

坑三:

有些项目在ci cd 的yaml文件中没有使用tags制定runner,导致有些项目无法找到runner

解决方法是在gitlab runner的配置页面中开启如下选项:


你可能感兴趣的:(如何部署docker excutor gitlab runner)