Docker how to run a container with specific name servers in / etc / resolv.conf

Here is my Dockerfile

FROM javamachine_0.1.2
MAINTAINER Meiram
RUN /report/report.sh start
ENV LANG C.UTF-8 ENV LANGUAGE C.UTF-8 ENV LC_ALL C.UTF-8
RUN echo "nameserver 192.168.1.100" > /etc/resolv.conf
COPY resolv.conf /etc/resolv.conf
EXPOSE 9090

when creating docker launch for container directives --dns also do not change entries in the /etc/resolv.conf file

How to change entries in /etc/resolv.conf permanently?

+4
source share
4 answers

if you use --dns, you may need to remove these lines:

RUN echo "nameserver 192.168.1.100" > /etc/resolv.conf
COPY resolv.conf /etc/resolv.conf

also,

try also swapping. The COPY command will override the previous one.

+1
source

I found the answer

When you need to create a container with default network settings (172.0.0.x)

- dns. --net some_name_of_your_network

, , /etc/hosts

docker run --net my_net --ip 192.168.1.x --add-host webserver:192.168.1.100 --add-host mysqlserver:192.168.1.x -td someimage

. /etc/resolv.conf

+1

. https://docs.docker.com/engine/userguide/networking/default_network/configure-dns/.

docker, --add-host ( , DNS)

--dns=192.168.1.100

, , - mysqlserver , docker-compose. . https://docs.docker.com/compose/overview/.

+1
source

If you use docker-compose, you can simply add your dns server to the docker-compose.yml file

  my-app:
     build: my-app
     dns:
       - 10.20.20.1  # dns server 1
       - 10.21.21.2  # dns server 2
     dns_search: ibm-edv.ibmnet.int

see https://bitbucket.org/snippets/mountdiablo/9yKxG/docker-compose-reference-yaml-file-with

+1
source

All Articles