【问题标题】:gitlab-ci add --net=host option to dockergitlab-ci 将 --net=host 选项添加到 docker
【发布时间】:2016-08-03 08:05:48
【问题描述】:

我开发了一个 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 选项?

谢谢。

【问题讨论】:

  • 看起来这还不可能。这是 gitlab.com 上的一个未解决问题,与您提到的相同问题 gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/903
  • 哪个主机名或什么不工作? (也许还有其他方法可以解决您的问题)
  • 实际上我的服务器在防火墙后面,我的 DNS 被重定向到公共 IP。它从外部网络工作正常,但从服务器我应该重定向本地 IP '10.x.x.x' 上的 DNS。你知道我的意思吗?
  • 2 年后,gitlab-ci.yml 中仍然无法指定--net=host

标签: docker gitlab gitlab-ci


【解决方案1】:

您需要在 docker 映像本身中使用 network_mode 参数,方法是编辑 config.toml 文件,如 gitlab-runner advanced configuration docs 中所述(有些糟糕)。

你也可以在创建 docker 镜像时这样做:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 2019-02-23
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    相关资源
    最近更新 更多