gitlab-ci在docker中添加--net=host选项

4

我正在开发一个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容器中没有解析。

我在这里找到了解决方案:如何让docker容器使用主机的/etc/hosts文件?

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

谢谢。


看起来目前还不可能。这里有一个在gitlab.com上的开放问题,与您提到的相同的问题 https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/903 - Jawad
主机名有什么问题?或者出现了什么具体错误?(也许有其他方法可以解决你的问题) - tmt
实际上我的服务器在防火墙后面,我的DNS被重定向到公共IP。从外部网络访问正常,但是从服务器访问时,我需要将DNS重定向到本地IP“10.x.x.x”。你知道我是什么意思吗? - barden
两年后,仍然无法在gitlab-ci.yml中指定--net=host吗? - Guillaume
1个回答

4
您需要在docker镜像本身中使用network_mode参数,通过编辑config.toml文件来实现,具体方法可以参考gitlab-runner的高级配置文档(描述可能不太清晰)。
您也可以在创建docker镜像时进行设置: gitlab-runner register --docker-network-mode 'host' 我认为您不能直接从gitlab yml文件中设置它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接