title: Docker/Hibernate/PostgreSQL - Connecting container running Hibernate/SpringBoot app with a postgreSQL container not working
body: <p>I'm running a very simple SpringBoot app that uses Hibernate to connect to a PostgreSQL db. And running two Docker containers, one with the .war with a Tomcat image and one with a postgresql image.</p>
  
  <p>This is the docker-compose file:</p>
  
  <pre><code>version: '3'
  
  services:
    spring2:
      build:
        context: .
        dockerfile: DockerfileTomcat
      ports:
        - 8080:8080
      depends_on:
        - db
      networks:
        - datalink
  
    db:
      image: postgres
      ports:
        - 5432:5432
      env_file:
        - psql.env
      volumes:
        - database:/var/lib/postgresql/data
      networks:
        - datalink
  
  networks:
    datalink:
      driver: bridge
  
  volumes:
    database:
  </code></pre>
  
  <p>And this is the hibernate.cfg.xml in the war:</p>
  
  <pre><code>&lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQL9Dialect&lt;/property&gt;
    &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
    &lt;property name="connection.url"&gt;jdbc:postgresql://db:5432/myappdb&lt;/property&gt;
    &lt;property name="connection.username"&gt;admin&lt;/property&gt;
    &lt;property name="connection.password"&gt;pass1234&lt;/property&gt;
    &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  
    &lt;mapping class="(...).models.Employee"/&gt;
  </code></pre>
  
  <p>So when I run the app with Eclipse in my host machine, connecting to the docker image, it works, but when I run it with Docker, using the docker compose, the endpoints that use the DB connection and Hibernate return 404.</p>
  
  <p>And the most confusing part is that no Errors show up. It just says that the endpoint is not found.</p>
  
  <p>Can anyone help?</p>