docker how to pass params to spring boot application

To pass parameters to a Spring Boot application running in a Docker container, you can follow these steps:

  1. Create an application.properties file: In your Spring Boot application, create an application.properties file (or application.yml if you prefer YAML format) in the src/main/resources directory. This file will hold the parameters you want to pass to your application.

  2. Define the parameters: Inside the application.properties file, define the parameters using the following format: parameterName=parameterValue. Replace parameterName with the name of the parameter you want to pass, and parameterValue with the actual value you want to assign to the parameter.

  3. Build your Docker image: Use the Dockerfile to build your Docker image. Make sure to include the application.properties file in the Docker image by copying it to the appropriate location in the Dockerfile.

  4. Run the Docker container: Start your Docker container using the docker run command. To pass the parameters to your Spring Boot application, add the -e flag followed by the parameter name and value. For example: docker run -e parameterName=parameterValue your-image-name.

  5. Access the parameters in your Spring Boot application: In your Spring Boot application, you can access the parameters using the @Value annotation. For example, if you defined a parameter called database.url in your application.properties file, you can access it in your application using @Value("${database.url}").

By following these steps, you can pass parameters to a Spring Boot application running in a Docker container. This allows you to customize the behavior of your application without modifying the code.