0

I need to develop a Spring Boot microservice and need to deploy in Docker. Now I developed a sample microservice. When I am learning Docker and container deployment I found many documentations for installing Docker and building images and running the application as container packaging. Here I have some doubts in deployment procedure:

  • If I need to deploy 4 Spring Boot microservice in Docker, do I need to create separate image for all? Or can I use the same Docker file in all my Spring Boot microservices?

  • I am using PostgreSQL database. So can I include that connection into Docker image file? Or I need to manage separately?

1

2 Answers 2

2
  • If you have four different Spring Boot applications, I suggest creating four different Dockerfiles, and building four different images from those files. Basically put one Dockerfile in each Spring application folder.
  • You can build PostgreSQL credentials (hostname, username & password) into the application by writing it in the code. This is easiest.

If you use AWS and ECS (Elastic Container Service) or EC2 to run your Docker containers you could store the credentials in the EC2 Parameter Store, and have your application fetch them at startup, however this takes a bit more AWS knowledge and you have to use the AWS SDK to fetch the credentials from the application. Here is a StackOverflow question about exactly this: Accessing AWS parameter store values with custom KMS key Ask Question

Sign up to request clarification or add additional context in comments.

1 Comment

Ok Sir. Thank you for your response. I have One Ec2 machine. I am now exploring that cloud section also. Currently I only used Elastic Beanstalk for deploying my sample service its working. But I am looking for Container service to launch my microservices. I am preferring Ec2 launch type instead of fargate launch from AWS ECS. I need to customize launching only from my EC2 machine. So I need to know docker from base. And also my services are spring cloud. I including Zuul,Eureka and hystrix. So I have my 4 services + spring cloud tool project. So I am totally confused to use dockers.
0
  1. There can be one single image for your all micro-services but its not a good design and not suggested. Always try to decoupled the things one from another. In your case, create separate images(separate Dockerfile) for each micro-service.
  2. Again same thing for your second question, create a separate image(one Dockerfile) for your database as well. And for the credentials, you can follow the Jonatan's suggestion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.