gitlab-ci add --net = docker的host选项

时间:2016-08-03 08:05:49

标签: docker gitlab gitlab-ci

我开发了一个php symfony项目,我使用gitlab。 我想在gitlab上构建单元测试,为此我使用gitlab-ci.yml文件:

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/

目前无法正常工作,因为我的主机名未在docker容器上解析。

我在这里找到了解决方案:How can you make the docker container use the host machine's /etc/hosts file?

我的问题是:我在哪里写--net = host选项?

感谢。

1 个答案:

答案 0 :(得分:1)

您需要使用泊坞窗图片本身中的network_mode参数,方法是将config.toml文件编辑为gitlab-runner advanced configuration docs中描述的(稍微差一点)。

您也可以在创建泊坞窗图像时执行此操作:

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

我不相信你可以直接从gitlab yml文件中设置它。