Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the hostname for docker container when using Gitlab CI

I'm trying to setup a Gitlab CI pipeline using docker image. For some reason, I need to set the host name of the docker container to a special value.

When running docker container locally, this can be done by specifying the -h|--hostname option. But in gitlab's official help document, it seems that only 'name' and 'entrypoint' keywords are supported for setting 'image' in .gitlab-ci.yml file.

Is there anyway to set the docker container's host name?

like image 603
dourensei Avatar asked Nov 01 '25 18:11

dourensei


1 Answers

Finally I found one solution from this page by myself: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersdocker-section

Here are my steps:

  1. Run 'gitlab-runner register' to register a runner and select docker as executor.
  2. Open /etc/gitlab-runner/config.toml file.
  3. Insert 'hostname = "xxxx"' into the '[runners.docker]' section of the registered runner.

To restrict the docker containers that will use the hostname set in step 3, you can:

  • Insert 'allowed_images = ["xxx:xxx"]' into the '[runners.docker]' section of the registered runner.
  • Set some tag for the runner and specify the 'tags' together with 'image' in .gitlab-ci.yml file.
like image 129
dourensei Avatar answered Nov 04 '25 11:11

dourensei