title: Connect to another container using Docker compose
body: <p>I need to use two containers together: one with Tomcat and another with a Database. </p>
  
  <p>I have created the following yaml file which describes the services:</p>
  
  <pre><code>postgredb:
    image: postgres
    expose:
      - 5432
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
  tomcat:
    image:  tomcat
    links:
      - postgredb:db
    ports:
      - 8080:8080
  </code></pre>
  
  <p>After starting docker-compose I can see that I'm not able to reach the Database from Tomcat, unless I retrieve the IP address of the Database (via docker inspect) and use it when configuring Tomcat Connection Pool to the DB.</p>
  
  <p>From my understanding, the two containers should be linked and I'd expect to find the database on localhost at port 5432, otherwise I see little benefits in linking the containers.</p>
  
  <p>Is my understanding correct?</p>