title: How do I set up linkage between Docker containers so that restarting won't break it?
body: <p>I have a few Docker containers running like:</p>
  
  <ul>
  <li>Nginx</li>
  <li>Web app 1</li>
  <li>Web app 2</li>
  <li>PostgreSQL</li>
  </ul>
  
  <p>Since Nginx needs to connect to the web application servers inside web app 1 and 2, and the web apps need to talk to PostgreSQL, I have linkages like this:</p>
  
  <ul>
  <li>Nginx --- link ---> Web app 1</li>
  <li>Nginx --- link ---> Web app 2</li>
  <li>Web app 1 --- link ---> PostgreSQL</li>
  <li>Web app 2 --- link ---> PostgreSQL</li>
  </ul>
  
  <p>This works pretty well at first. However, when I develop a new version of web app 1 and web app 2, I need to replace them. What I do is remove the web app containers, set up new containers and start them.</p>
  
  <p>For the web app containers, their IP addresses at first would be something like:</p>
  
  <ul>
  <li>172.17.0.2</li>
  <li>172.17.0.3</li>
  </ul>
  
  <p>And after I replace them, they will have new IP addresses:</p>
  
  <ul>
  <li>172.17.0.5</li>
  <li>172.17.0.6</li>
  </ul>
  
  <p>Now, those exposed environment variables in the Nginx container are still pointing to the old IP addresses. Here comes the problem. How do I replace a container without breaking linkage between containers? The same issue will also happen to PostgreSQL. If I want to upgrade the PostgreSQL image version, I certainly need to remove it and run the new one, but then I need to rebuild the whole container graph, so this is not ideal for real-life server operation.</p>