如何为GitLab Runner设置名称服务器

huangapple go评论83阅读模式
英文:

How to set nameserver for the gitlab-runner

问题

我在.gitlab-ci.yml文件中有以下配置:

image: docker:20.10.16
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables: 
  DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_DRIVER: overlay2

services:
    - docker:20.10.16-dind

pages:
  stage: deploy
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apk add --update openssh )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan $REPO_IPADDRESS >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - docker info
  script:
    - docker --version
    - docker-compose -f docker-compose.prod.yaml up -d
  artifacts:
    paths:
      - public
  only:
    - main

如何为我的gitlab-runner设置名称服务器或使其使用运行它的操作系统的名称服务器?

英文:

I have the following configuration in .gitlab-ci.yml file:

image: docker:20.10.16
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables: 
  DOCKER_TLS_CERTDIR: "/certs"
  DOCKER_DRIVER: overlay2
  
services:
    - docker:20.10.16-dind

pages:
  stage: deploy
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apk add --update openssh )' 
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan $REPO_IPADDRESS >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - docker info
  script:
    - docker --version
    - docker-compose -f docker-compose.prod.yaml up -d
  artifacts:
    paths:
      - public
  only:
    - main

How can I set nameserver for my gitlab-runner or make it use the nameserver of the OS that it is running on?

答案1

得分: 1

使用正在运行的操作系统的命名服务器

这应该是默认行为,根据我的经验,它也适用于GitLab的docker-in-docker,无需额外配置 - 查询会被转发到主机的DNS服务器。根据Docker文档:

默认情况下,容器继承主机的DNS设置,如/etc/resolv.conf配置文件中定义的设置。连接到默认bridge网络的容器会获得此文件的副本。连接到自定义网络的容器会使用Docker的内置DNS服务器。内置DNS服务器将外部DNS查询转发到主机上配置的DNS服务器。

但无论如何,您可以在GitLab docker runner管理的容器中明确配置DNS,使用[runners.docker]部分配置中的dnssearch_dns选项。

英文:

> use the nameserver of the OS that it is running on

That should be the default behavior and, in my experience, also works with GitLab's docker-in-docker without any additional configuration -- lookups get forwarded to the host's DNS servers. Per the docker docs:

> By default, containers inherit the DNS settings of the host, as defined in the /etc/resolv.conf configuration file. Containers that attach to the default bridge network receive a copy of this file. Containers that attach to a custom network use Docker’s embedded DNS server. The embedded DNS server forwards external DNS lookups to the DNS servers configured on the host.

But in any case, you can explicitly configure DNS for containers that the GitLab docker runner manages with the dns and search_dns options in the [runners.docker] section configuration.

huangapple
  • 本文由 发表于 2023年7月17日 19:21:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定