May 22, 2021 Docker From entry to practice
Docker doesn't customize the image specifically for each container, so how do you customize the host name and DNS configuration of the configuration container? The secret is that it uses virtual files to mount the three related profiles of the incoming container.
The mount information can be seen in the container using the mount command:
$ mount
...
/dev/disk/by-uuid/1fec...ebdf on /etc/hostname type ext4 ...
/dev/disk/by-uuid/1fec...ebdf on /etc/hosts type ext4 ...
tmpfs on /etc/resolv.conf type tmpfs ...
...
This mechanism allows the dns configuration of all Docker containers to be updated immediately through
/etc/resolv.conf
as soon as the host host DNS information is updated.
If the user wants to manually specify the configuration of the container, they can take advantage of the following options.
-h HOSTNAME or --hostname=HOSTNAME
host name of the container, which is
/etc/hostname
/etc/hosts
However, it is not visible outside the
docker ps
nor in
/etc/hosts
--link=CONTAINER_NAME:ALIAS
host name of a different container
/etc/hosts
container to connect to it using the host name ALIAS.
--dns=IP_ADDRESS
a DNS server
/etc/resolv.conf
which the container uses to resolve
/etc/hosts
--dns-search=DOMAIN
domain for the container, and when the
.example.com
DNS searches not only for hosts, but also
host.example.com
Note: Without the last 2 options above, Docker will configure the
/etc/resolv.conf
on the host.