I want to be able to add hostnames to my laptop /etc/hosts that maps to a docker container. Since container ips are not static, each site I start/restart a container I would need to update the /etc/hosts file manually which is not very practical.
I am looking for a simple way to solve this. I could do some sort of script, which listens to docker events, checks for container ip and updates /etc/hosts but I dont want to reinvent the wheel. (something like this: https://github.com/discordianfish/docker-spotter) but I couldnt really understand how it works.
Anybody has a suggestion?. Thank you.
You can do that using in your docker-compose.yml using extra_hosts
. For instance:
version: '2'
services:
daemon:
build: ./
extra_hosts:
- "example.com:127.0.0.1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With