/docs/install/docker.md

https://gitlab.com/king6cong/gitlab-ci-multi-runner · Markdown · 117 lines · 87 code · 30 blank · 0 comment · 0 complexity · 4bf3b6a5bbb3b895fdc3a9a1ea63a2f3 MD5 · raw file

  1. ## Run gitlab-runner in a container
  2. ### Docker image installation and configuration
  3. Install Docker first:
  4. ```bash
  5. curl -sSL https://get.docker.com/ | sh
  6. ```
  7. We need to mount a config volume into our gitlab-runner container to
  8. be used for configs and other resources:
  9. ```bash
  10. docker run -d --name gitlab-runner --restart always \
  11. -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  12. gitlab/gitlab-runner:latest
  13. ```
  14. OR you can use a config container to mount your custom data volume:
  15. ```bash
  16. docker run -d --name gitlab-runner-config \
  17. -v /etc/gitlab-runner \
  18. busybox:latest \
  19. /bin/true
  20. docker run -d --name gitlab-runner --restart always \
  21. --volumes-from gitlab-runner-config \
  22. gitlab/gitlab-runner:latest
  23. ```
  24. If you plan on using Docker as the method of spawning runners, you will need to
  25. mount your docker socket like this:
  26. ```bash
  27. docker run -d --name gitlab-runner --restart always \
  28. -v /var/run/docker.sock:/var/run/docker.sock \
  29. -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  30. gitlab/gitlab-runner:latest
  31. ```
  32. Register the runner:
  33. ```bash
  34. docker exec -it gitlab-runner gitlab-runner register
  35. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
  36. https://gitlab.com/ci
  37. Please enter the gitlab-ci token for this runner
  38. xxx
  39. Please enter the gitlab-ci description for this runner
  40. my-runner
  41. INFO[0034] fcf5c619 Registering runner... succeeded
  42. Please enter the executor: shell, docker, docker-ssh, ssh?
  43. docker
  44. Please enter the Docker image (eg. ruby:2.1):
  45. ruby:2.1
  46. INFO[0037] Runner registered successfully. Feel free to start it, but if it's
  47. running already the config should be automatically reloaded!
  48. ```
  49. The runner should is started already and you are ready to build your projects!
  50. ### Update
  51. Pull the latest version:
  52. ```bash
  53. docker pull gitlab/gitlab-runner:latest
  54. ```
  55. Stop and remove the existing container:
  56. ```bash
  57. docker stop gitlab-runner && docker rm gitlab-runner
  58. ```
  59. Start the container as you did originally:
  60. ```bash
  61. docker run -d --name gitlab-runner --restart always \
  62. -v /var/run/docker.sock:/var/run/docker.sock \
  63. -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  64. gitlab/gitlab-runner:latest
  65. ```
  66. **Note**: you need to use the same method for mounting you data volume as you
  67. did originally (`-v /srv/gitlab-runner/config:/etc/gitlab-runner` or `--volumes-from gitlab-runner`)
  68. ### Installing Trusted SSL Server Certificates
  69. If your GitLab CI server is using self-signed SSL certificates then you should
  70. make sure the GitLab CI server certificate is trusted by the gitlab-ci-multi-runner
  71. container for them to be able to talk to each other.
  72. The `gitlab/gitlab-runner` image is configured to look for the trusted SSL
  73. certificates at `/etc/gitlab-runner/certs/ca.crt`, this can however be changed using the
  74. `-e "CA_CERTIFICATES_PATH=/DIR/CERT"` configuration option.
  75. Copy the `ca.crt` file into the `certs` directory on the data volume (or container).
  76. The `ca.crt` file should contain the root certificates of all the servers you
  77. want gitlab-ci-multi-runner to trust. The gitlab-ci-multi-runner container will
  78. import the `ca.crt` file on startup so if your container is already running you
  79. may need to restart it for the changes to take effect.
  80. ### Alpine Linux
  81. You can also use alternative [Alpine Linux](https://www.alpinelinux.org/) based image with much smaller footprint:
  82. ```
  83. gitlab/gitlab-runner latest 3e8077e209f5 13 hours ago 304.3 MB
  84. gitlab/gitlab-runner alpine 7c431ac8f30f 13 hours ago 25.98 MB
  85. ```
  86. **Alpine Linux image is designed to use only Docker as the method of spawning runners.**
  87. The original `gitlab/gitlab-runner:latest` is based on Ubuntu 14.04 LTS.