Skip to content

Instantly share code, notes, and snippets.

@NAR8789
Last active September 12, 2023 10:07
Show Gist options
  • Save NAR8789/92da076d0c35b434107fb4f4f198fd12 to your computer and use it in GitHub Desktop.
Save NAR8789/92da076d0c35b434107fb4f4f198fd12 to your computer and use it in GitHub Desktop.
wildcard dns for docker-compose using dnsmasq
# explicitly define host-ip mappings
address=/myapp.local/172.16.1.2
# dnsmasq entries are always wildcard entries, so this maps both myapp.local and *.myapp.local
# (yes, it's fine for this to be your entire dnsmasq config. the defaults are pretty sensible)
version: '2' # v2 required for ip_range config support. v3 won't work.
networks:
default:
ipam:
config:
- subnet: 172.16.0.0/23 # In order to specify static IPs, we must explicitly declare subnet.
ip_range: 172.16.0.0/24 # Range for dynamic IPs. We'll make sure to assign static IPs outside this range.
# docs: https://docs.docker.com/compose/compose-file/compose-file-v2/#ipam
# As of this writing, `ip_range` is not supported in v3.
services:
dnsmasq:
image: strm/dnsmasq
volumes:
- ./dnsmasq.conf:/etc/dnsmasq.conf
ports:
- 53:53/udp
cap_add:
- NET_ADMIN
# dnsmasq container config above is taken verbatim from https://hub.docker.com/r/strm/dnsmasq
networks:
default:
ipv4_address: 172.16.1.1 # Static IP here makes it possible to point other containers' dns here.
myapp:
# ...
# your app config here
# ...
networks:
default:
ipv4_address: 172.16.1.2 # Static IP here makes dnsmasq config easy to write.
appclient:
# ...
# more container config
# ...
dns:
- 172.16.1.1 # dnsmasq container
# `appclient` should now be able to access `myapp` as myapp.local or foo.myapp.local
@boomshadow
Copy link

@ppatidar-conga Sure. Here is what we use at my job. Everyone is able to have working wildcard DNS with this: https://gist.github.com/boomshadow/20677ef02f110e448ee058ae6149af3a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment