https://docs.docker.com/config/containers/container-networking/
Offcial documentation :
By default, a container inherits the DNS settings of the host, as defined in the /etc/resolv.conf
configuration file. Containers that use the default bridge
network get a copy of this file, whereas containers that use a custom network use Docker’s embedded DNS server, which forwards external DNS lookups to the DNS servers configured on the host.
Custom hosts defined in /etc/hosts
are not inherited.
!!Note: this means if you have public dns server that redirects xxx.com to public IP in /etc/resolv.conf and then you have private dns server that redirects xxx.com to prviate Ip for staging, docker will map xxx.com to public IP, where your server will map xxx.com to private IP
This default setting can be overriden by
1) /etc/daemon.json
https://stackoverflow.com/questions/44410259/how-do-i-configure-which-dns-server-docker-uses-in-docker-desktop-for-mac
https://docs.docker.com/engine/reference/commandline/dockerd/
https://docs.docker.com/get-started/overview/#:~:text=The%20Docker%20daemon%20(%20dockerd%20)%20listens,daemons%20to%20manage%20Docker%20services.
The Docker daemon ( dockerd ) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes.
https://robinwinslow.uk/fix-docker-networking-dns
Note:
You should create this file with the following contents to set two DNS, firstly your network’s DNS server, and secondly the Google DNS server to fall back to in case that server isn’t available:
/etc/docker/daemon.json:
{
"dns": ["10.0.0.2", "8.8.8.8"]
}
2) by adding additional dns recortds or server in docker-compose file
https://stackoverflow.com/questions/41717180/docker-compose-container-using-host-dns-server
custom dns:
version: '2.1'
services:
nexus:
image: sonatype/nexus3:$NEXUS_VERSION
container_name: nexus
restart: always
hostname: nexus.$URL
ports:
- "$NEXUS_81:8081"
- "$NEXUS_443:8443"
extra_hosts:
- "repos.private.network:192.168.200.200"
dns:
- 192.168.3.7
- 192.168.111.1
- 192.168.10.5
- 192.168.10.15
volumes_from:
- nexus-data
networks:
- pic
custom domain mapping :
https://fleio.com/docs/2022.05.1/faq/extra-hosts.html#:~:text=If%20you%20need%20to%20add,%2Fhome%2Ffleio%2Fcompose%20.&text=Finally%2C%20you%20need%20to%20run,order%20to%20apply%20the%20changes.
No comments:
Post a Comment