Docker compose DNS resolution
Docker Compose relies on an internal DNS server to manage and resolve service names across containers within a network.
Each container’s /etc/hosts file contains basic entries for local resolution, but inter-container communication is primarily handled through Docker’s internal DNS.
Each container is assigned a hostname that matches the service name defined in the docker-compose.yml file.
Docker’s internal DNS server keeps track of these hostnames and their corresponding container IP addresses. When a container needs to resolve another service’s name, it queries the internal DNS server.
Custom entries can be added to the
/etc/hosts file of containers using the extra_hosts option in the docker-compose.yml file.This allows you to define additional hostname-to-IP address mappings that will be included in each container's
/etc/hosts file.How works extra_hosts:- The
extra_hostsoption allows you to specify additional hostname-to-IP address mappings. - Each entry is defined in the format
hostname:ip_address.
- The
Example (docker-compose.yml file):
servicename:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: test
extra_hosts:
- "websrv.local:192.168.11.11"
Comentarii
Trimiteți un comentariu