Dockerize Spring Boot Java app with Kafka, Zookeeper, and MongoDB

I am a beginner to Docker and web applications in general. I have to Dockerize a Spring Boot Java app that uses Kafka, Zookeeper, and MongoDB. It also uses the Gradle build tool. I am thinking of first using Gradle to build the app into a JAR file. Then I will start Docker containers for Kafka, Zookeeper, and MongoDB. After that I will compose a Dockerfile to run the JAR file with something like this:

FROM java:7
ADD /javaApp/build/libs/javaApp.jar javaApp.jar
ENTRYPOINT [“java”, “-Dspring.config.location=‘location of Spring Boot config file’”, “-jar”,“javaApp.jar”]

After that, I have to get these different containers to link and talk to each other. What would be the best approach to do this? Should I use a Docker-Compose file perhaps?

Thanks!

If all containers run on the same node, you could connect them via the bridge network. Or the containers expose the ports and use the host network.

If containers will run on different nodes, you should use the overlay network.

You would want to run multiple replicas for Kafka, ZooKeeper and MongoDB. There is a good discussion about how to handle replication for them.