This utility helps you to configure docker containers IPs into host file to manage containers with hostname instead of IPs. Whther you want to access the container or redirect traffic to that container like using nginx, it worked. You don't have to configure or manually edit the host file to maintain the IPs.
Prerequisites
- Make sure you have docker installed on your machine and it is runing.
- Install
jq
utility. For example in Ubunut or debian based OSsudo apt install jq -y
Further Process
- Copy the content of
update-docker-hosts.sh
and paste it in/usr/local/bin/docker-update-hosts
. If there is no file exists, ceate new file and paste the content. - Set the executable permission with
chmod +x /usr/local/bin/docker-update-hosts
. - Copy the content of
docker-update-hosts.service
and paste it in/etc/systemd/system/docker-update-hosts.service
. If file doesn't exists, create new file and paste the content. - Enable and start the service by xecuting below commands.
sudo systemctl enable docker-update-hosts.service
sudo systemctl start docker-update-hosts.service
sudo systemctl status docker-update-hosts.service
This uses builtin process by watching on docker events to modify host file and it uses jq as json parser to fetch IPs from containers.