Archive June 2018

register and update docker containers ips in etc hosts

Use following script to update /etc/hosts with entries of docker containers mycontainersXXXXwitr.local

# delete lines between '# docker-compose containers start' and '# docker-compose containers end' in /etc/hosts
sudo sed -i.bak '/^# docker-compose containers start/,/# docker-compose containers end/d' /etc/hosts


echo -e "\nyour /etc/hosts is updated with following:"
echo "======================"
echo "" | sudo tee -a /etc/hosts
echo "# docker-compose containers start" | sudo tee -a /etc/hosts
echo "" | sudo tee -a /etc/hosts
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{.Name}}' $(docker ps --filter name=mycontainers.*witr.local -q) | sed 's/\///' | sudo tee -a /etc/hosts
echo "" | sudo tee -a /etc/hosts
echo "# docker-compose containers end" | sudo tee -a /etc/hosts
echo "======================"