I would need to use two containers together: one with Tomcat and another with a Database. I have created the following yaml file which describes the services:
postgredb:
image: postgres
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
tomcat:
image: tomcat
links:
- postgredb:db
ports:
- 8080:8080
Once started 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. 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. Is my understanding correct ? Any guidance will be much appreciated!