1

Say I have a docker compose file like this:

version: '2'
services:
  randomDNStest:
    dns: 
      - ###.###.###.###
    network_mode: "host"
    build: .

and a Dockerfile like this:

FROM gitlab/gitlab-runner

RUN ["gitlab-runner", "register", "--non-interactive", "--url", "THE INTERNAL GIT LAB INSTANCE", "--registration-token", "MY TOKEN", "--executor", "docker", "--tag-list", "docker", "--description", "DESCRIPTION", "--docker-image",  "docker:19.03.1", "--docker-dns", "###.###.###.###",  "--docker-privileged", "--docker-tlsverify", "--docker-volumes", "/certs/client"]

How can I specify the DNS server for the Dockerfile to use at build time (in the run command)?

Things similar to what I want but not right:

  • Using docker run --dns.
    • Doesn't work with docker-compose.
  • Modifying the DNS service on the host to listen on a non-localhost address that is reachable from within the container as described here and implemented here.
    • Probably works, but requires set-up on the host.
  • Using the dns section in docker-compose as shown above.
    • This works at run-time, not build-time.
  • Using curl's --dns-servers parameter with the parameters described here
    • Curl command format: curl -X POST -F token=QytSH_88wASA_LA6G2mf --dns-servers ###.###.###.### https://INTERNAL_GIT_LAB//api/v4/runners
    • Curl's --dns-servers command must be compiled in as described in the curl docs and in Nathan Leclaire's blog, but I couldn't get the dependencies right, and this only avoids using the problem for my specific use case.
  • Using the network_mode: "host" driver as shown above and described here
    • This doesn't work.
mikeLundquist
  • 769
  • 1
  • 12
  • 26

1 Answers1

1

You do not want to run this command in your Dockerfile. The basic concept there is that you can docker build an image once, and then docker run multiple copies of that container, or push the image to a registry and run it from other systems. A GitLab runner image that once upon a time has been registered with some particular server isn't especially useful to re-docker run later on.

The GitLab documentation for this image suggests it isn't intended to be used as a base image at all. You can just put the command and other settings in your docker-compose.yml file

version: '2'
services:
  randomDNStest:
    dns: 
      - ###.###.###.###
    command: >-
      register
      --non-interactive
      --url THE_INTERNAL_GITLAB_INSTANCE
      ...

(If this returns immediately, re-running docker-compose up will repeat the command.)

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • When I do this, I get `gitlab-runner | Registering runner... succeeded runner=` ... `gitlab-runner | Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!` `gitlab-runner exited with code 0` – mikeLundquist Aug 09 '19 at 18:26
  • Registration does work, but the runner isn't started – mikeLundquist Aug 09 '19 at 18:29
  • Oh, I need to add `gitlab-runner run`... doh – mikeLundquist Aug 09 '19 at 18:33
  • Wait, actually I can only run one command, so I can't use `run` after registering – mikeLundquist Aug 09 '19 at 18:41
  • Ok, it looks like I can just add another container for a second command https://stackoverflow.com/questions/30063907/using-docker-compose-how-to-execute-multiple-commands#30064175 – mikeLundquist Aug 09 '19 at 18:47