4

I developp a php symfony project and I use gitlab. I want to build the unit test on gitlab, for that I use gitlab-ci.yml file :

image: php:5.6

 # Select what we should cache
 cache:
   paths:
   - vendor/

 before_script:
 # Install git, the php image doesn't have installed
 - apt-get update -yqq
 - apt-get install git -yqq

 # Install mysql driver
 - docker-php-ext-install pdo_mysql

 # Install composer
 - curl -sS https://getcomposer.org/installer | php

 # Install all project dependencies
 - php composer.phar install

 services:
 - mysql

 variables:
   # Configure mysql service (https://hub.docker.com/_/mysql/)
   MYSQL_DATABASE: hello_world_test
   MYSQL_ROOT_PASSWORD: mysql

 # We test PHP5.5 (the default) with MySQL
 test:mysql:
   script:
  - phpunit --configuration phpunit_mysql.xml --coverage-text -c app/

It currently doesn't work because my hostname isn't resolved on the docker container.

I found the solution here : How can you make the docker container use the host machine's /etc/hosts file?

My question is : Where do I write the --net=host option ?

Thanks.

Community
  • 1
  • 1
barden
  • 349
  • 6
  • 18
  • Looks like this is not possible yet. Here's an open issue on gitlab.com with the same problem you mention https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/903 – Jawad Aug 03 '16 at 08:15
  • Which hostname or what exactly doesn't work? (maybe there is some other way to tackle your problem) – tmt Aug 03 '16 at 08:18
  • Actually my server is behind firewall, my DNS is redirect to the public IP. It work fine from external network, but from the server I should redirect the DNS on the local IP '10.x.x.x'. You know what I mean ? – barden Aug 03 '16 at 08:39
  • 2 years later, still not possible to specify `--net=host` in `gitlab-ci.yml`? – Guillaume Jun 08 '18 at 10:24

1 Answers1

4

You need to use the network_mode parameter in the docker image itself, by editing the config.toml file as (somewhat poorly) described in the gitlab-runner advanced configuration docs.

you can also do it when you create the docker image:

gitlab-runner register --docker-network-mode 'host'

I don't believe you can set it directly from the gitlab yml file.

Tim Rae
  • 3,167
  • 2
  • 28
  • 35