When you first register your Gitlab runner to use the Docker executor, you may run into the following issues:
- Problem1: You get a host unknown error when the runner attempts to checkout code: fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@my.server.com/my-projects/my-project.git/': Couldn't resolve host 'my.server.com'. Chances are you are not running a local DNS server that your Docker container can use to resolve my.server.com.
- Problem 2: Everything is setup correctly but Gitlab runner always attempts to pull Docker images from Docker Hub.
- Problem 3: Gitlab runner may complain that you are checking out code in the root directory.
Below is a solution to each of the 3 stated problems above.
We will make the following assumptions for the purpose of this example:
- Gitlab runner can access Gitlab server.
- Local Docker image: my_runner_image
- Hostname of machine hosting my Gitlab server: my.server.com
- IP address of machine hosting my Gitlab server: 192.168.1.144
- Default Gitlab runner configuration file: /etc/gitlab-runner/config.toml
- If you have a home network and lack a DNS Server, it is preferable to set a fixed IP address for your machines.
Solutions:
concurrent = 1
check_interval = 0
[[runners]]
name = "myRunner"
url = "http://192.168.1.144/ci"
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
[runners.docker]
tls_verify = false
image = "my_runner_image:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
[runners.cache]
The goal here is tell the container how to resolve my.server.com which the Gitlab runner will inject in the Docker container. Add “extra_hosts” as an extra variable in the configuration:
[[runners]]
name = "myRunner"
url = "http://192.168.1.144/ci"
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
[runners.docker]
extra_hosts = ["my.server.com:192.168.1.144"]
tls_verify = false
image = "my_runner_image:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
[runners.cache]
- Gitlab runner has the concept of a pull policy of either always attempting to download the image from the registry, download if not available locally or never download. By default, it always attempts to download images so if you are trying to use an image you have built locally, it will fail. The best option is to download when not available:
[[runners]]
name = "myRunner"
url = "http://192.168.1.144/ci"
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
[runners.docker]
extra_hosts = ["my.server.com:192.168.1.144"]
pull_policy = "if-not-present"
tls_verify = false
image = "my_runner_image:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
[runners.cache]
RUN mkdir -p /my_build_directory
Specify in the Gitlab runner configuration file the build directory:
[[runners]]
name = "myRunner"
url = "http://192.168.1.144/ci"
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
builds_dir = "/my_build_directory"
[runners.docker]
extra_hosts = ["my.server.com:192.168.1.144"]
pull_policy = "if-not-present"
tls_verify = false
image = "my_runner_image:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
[runners.cache]
The code will now be checked out in /my_build_directory
If you have any questions or feedback, please do not hesitate to drop a note!
If you have any questions or feedback, please do not hesitate to drop a note!
I am very new to GitLab. I have been attempting to run a tutorial on DigitalOcean for the past month without sucess. I have tried and many different things.This is my problem
ReplyDeleteRunning with gitlab-runner 11.7.0 (8bb608ff)
on Amp 5ttJehsD
Using Docker executor with image node:carbon ...
Pulling docker image node:carbon ...
Using docker image sha256:xzxzxzx
for node:carbon ...
Running on runner-5ttJehsD-project-19-concurrent-0 via sari...
Cloning repository...
Cloning into '/builds/myserver/hello_hapi'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlabserver.myserver.com/myserver/hello_hapi.git/': The requested URL returned error: 500
/bin/bash: line 62: cd: /builds/server/hello_hapi: No such file or directory
ERROR: Job failed: exit code 1
Have you set the extra_hosts variable?
ReplyDeleteOn this post, I have set it as "extra_hosts = ["my.server.com:192.168.1.144"]"
In your case, it should be "extra_hosts = ["gitlabserver.myserver.com:192.168.1.144"]" along with whatever IP address of the host running gitlab.