dockerizing spring boot application
Download and install docker desktop
Follow the steps provided in the docker docs to install and setup docker desktop docs.docker.com
Create 2 Rest applications
Order service dependency:
Create a controller class and expose an endpoint:
Run the application on any port. I’ve run it on port 9010 by setting the server.port property in application.properties file. And hit the endpoint from browser:
Product Service dependency
Create a controller class and expose an endpoint:
Run the application on any port. I’ve run it on port 9011 by setting the server.port property in application.properties file. And hit the endpoint from browser:
Creating Docker files, building images and running containers
Build both the projects and create a Dockerfile in both the projects and specify the commands as follows:
Now build the image and run the container using the following command for order Service:
Now build the image and run the container using the following command for Product Service:
When you access the order service and product service endpoints now, they should be accesible from containers.
We can see our images in docker desktop:
Containers:
Logs: