Configuring DNS
Docker provides hostname and DNS configuration for each container without building a custom image. It overlays the /etc
files inside the container with virtual files where it can write new information.
This can be seen by running the mount
command inside the container. Containers receive the same /resolv.conf
as of the host machine when they are created initially. If a host's /resolv.conf
file is modified, it will be reflected in the container's /resolv.conf
file only when the container is restarted.
In Docker, you can set the dns
options in two ways:
Using
docker run --dns=<ip-address>
In the Docker daemon file, add
DOCKER_OPTS="--dns ip-address"
Tip
You can also specify the search domain using --dns-search=<DOMAIN>
.
The following diagram shows the nameserver being configured in container using the DOCKER_OPTS
setting in the Docker daemon file:
DOCKER_OPTS being used to set nameserver setting for Docker container
The main DNS files are as follows:
/etc/hostname /etc...