My docker-compose.yml file looks something like this:
version: "3"
services:
redis:
networks:
- backend
....
activemq:
networks:
- backend
....
mainapp:
build: .
networks:
- backend
depends_on:
- redis
- activemq
.....
networks:
backend:
My mainapp is a scala app which needs IP of Redis & ActiveMq, how can i pass IP of these services to my mainapp?
You can directly use the name of the service you created, Docker will automatically resolve the corresponding IP.
In your case you can use redis(defined on ln 4) in your configuration instead of the real IP. For example: REDIS_HOST=redis, depending on your configuration structure.