-
-
Save Schm1tz1/5f10ca18520d5870329d01ae3af4803c to your computer and use it in GitHub Desktop.
wildcard dns for docker-compose using dnsmasq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment