2 Containers, one Java application and the second mongodb.
If I run my java app locally and mongodb in a container, it connects but if both run inside a container, java
You probably cant connect because you set the MONGO_HOST as localhost and mongo is a linked service.
MONGO_HOST
localhost
In order to use linked services network, you must specify the MONGO_HOST as the name of the service - mongo, like that:
mongo
MONGO_HOST=mongo