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 container directive docker run --dns also do not change entries in /etc/resolv.conf
How to change entries in /etc/resolv.conf permanently?
If you use docker-compose you can simple add your dns-server in docker-compose.yml
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
if you use --dns you may need to remove those lines:
RUN echo "nameserver 192.168.1.100" > /etc/resolv.conf
COPY resolv.conf /etc/resolv.conf
also,
try to swap the lines too.. COPY command will override the previous one.
I found the answer
When you need to create a container with default network settings (172.0.0.x)
The key --dns is working. But doesn't work with user-defined network --net some_name_of_your_network
So if you need to create container you can define hostnames in /etc/hosts
using this command
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
But this solution is not acceptable for me. Because I need to edit /etc/resolv.conf
See https://docs.docker.com/engine/userguide/networking/default_network/configure-dns/ for more details.
You'll want to add the following to your docker command line, instead of all the --add-host
options (assuming that your hosts are resolvable through your dns)
--dns=192.168.1.100
Based on the fact that you're running multiple services, if your webserver and mysqlserver are also docker containers, you might want to configure the collection of containers via docker-compose. See https://docs.docker.com/compose/overview/ for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With