Build a simple web applicaiton with spring boot with docker
-
Create a spring boot webapp from https://start.spring.io/ . spring boot allows user to create spring framework web applicaion quickly.
-
On application.properties file (applicaion.yaml for gradle project) add the follow.
spring.data.mongodb.host=mongo
-
Make a war Package
mvn clean package
-
Create a dockerfile
docker built -t imagename .
- Check the image
docker images
docker-compose up
- the docker-compose script will download mongodb image from dockerhub and generate a mongodb image for us. It will also run the database image first before our app. Our app will connect to mongodb with mongo:27017. Once finish, open localhost:8080 to check out the web application.
references: spring-boot-docs