Mike Hughes
Mike Hughes

Reputation: 21

How to refresh docker-compose external_links dns

I have services defined in three docker-compose files. One with services, the other two are blue and green instances of my application.

All share the same external networks, and services are exposed between compose files using external_links

Occasionally when flipping between blue and green, the IP changes I need to restart the services to update the IP on the service containers.

Is there anyway to update the the docker links dynamically, so I do not have to restart my nginx container, creating a period of unavailability?

Upvotes: 0

Views: 861

Answers (1)

BMitch
BMitch

Reputation: 263856

Links are the wrong way to do this. Links work by modifying the host file of the container, but that modification does not update as the target container gets replaces. They have been largely deprecated because of various issues like this.

Remove the links from your compose file, and place containers on a common user created network (i.e. not one of the several default docker provided networks). Out of the box, compose will give you a user created network for your services (the default network named ${project}_default that you can see with docker network ls), or you can specify external networks when you are connecting containers from multiple projects.

With the shared network, docker will give you DNS resolution based on the container name and any network aliases. With docker-compose you will have network aliases configured out of the box for the service names. So if you have a service named "web" you can run curl http://web:8080 to hit port 8080 on any of the replicas of the "web" service. This user experience is identical if you transition to swarm mode, though it is implemented with a VIP, rather than DNS-RR, which handles issues like cached DNS entries during a rolling update.

Upvotes: 1

Related Questions