Docker Compose Tip #65: Custom DNS configuration with dns and dns_search
By default, containers inherit DNS configuration from the Docker daemon. When you need to override that, three directives give you full control: dns:, dns_search:, and dns_opt:. Setting custom DNS servers dns: overrides which resolvers the container queries: services: app: image: myapp dns: - 1.1.1.1 - 8.8.8.8 The container now uses Cloudflare and Google DNS instead of whatever the host provides. Useful when: The host DNS is slow or unreliable for your use case You need a specific public DNS for content filtering (Pi-hole, NextDNS) A development environment must reach internal services through a corporate DNS server Search domains dns_search: adds search domains so short names resolve against them: ...