mikeLundquist
mikeLundquist

Reputation: 1009

How can I tell my Dockerfile what DNS to use in RUN commands from docker-compose?

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:

Upvotes: 1

Views: 2334

Answers (1)

David Maze
David Maze

Reputation: 158977

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.)

Upvotes: 1

Related Questions