I was reading a docker script someone else created and came across an interesting blog explaining a parameter it used (–add-host) right here. I recommend reading that longer blog, but I’m recording the short notes and link here for myself as I’m sure I’ll be using this a lot.
The “–add-host” Parameter
Long story short, you can just add “–add-host=some_dns_name:some_ip_address” to your docker command in order to make your container have any DNS name resolve to any IP address.
This works by having the container put an entry for this DNS/IP pair into the /etc/hosts file.
Use Outside of Docker
I haven’t used the /etc/hosts file in a while. But this reminded me about it. The article points out that you can either add a DNS mapping or even override an existing DNS mapping using this file.
So, for example, I could make google.com point at this website from within the given OS instance, if I updated that file properly.
Pretty cool and useful :).