title: Share IP between containers using docker-compose
body: <p>I use docker-compose to link containers. The structure looks like this:</p>
  
  <pre><code>version: '3.3'
  services:
    db_service:
      ...
    api_service:
      ...
    ...
  </code></pre>
  
  <p>I know Nginx can access the IP of other containers using the following code:</p>
  
  <pre><code>location /api/ {
      proxy_pass      http://api_service:5000;
  }
  </code></pre>
  
  <p>I would like to extend this <a href="https://stackoverflow.com/questions/49369272/share-ip-address-between-docker-containers">question</a> where a concrete example would have been appreciated.</p>
  
  <p>In my situation, I would like to connect to a database located in another container. The IP of the database is given by: <code>$ docker inspect my_db | grep "IPAddress"</code> and it is not constant over different runtimes. The code below works currently but I am looking for something more robust which resists a simple reboot and is ideally reusable at every stage of the cycle (development, test, deploy).</p>
  
  <pre><code>conn = psycopg2.connect("dbname=postgres user=postgres password=postgres host=172.25.0.2")
  </code></pre>