The implementation of docker was correct. The issue I was facing was due to docker creating wrong image of my spring app.
If I run both images on the same network, they are able to communicate with each other now!