我开发了一个 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 选项?
谢谢。
您需要使用 docker 镜像本身中的
network_mode
参数,方法是按照 gitlab-runner 高级配置文档中所述编辑
config.toml
文件(有点糟糕)。
您也可以在创建 docker 镜像时执行此操作:
gitlab-runner register --docker-network-mode 'host'
我不相信你可以直接从gitlab yml文件中设置它。