I want to run a Docker container with some data source arguments the way I run a Spring Boot app on the terminal with Spring data source arguments. For example:
java -Dserver.port=8999 -Dlogging.org.hibernate.SQL=DEBUG -Dlogging.level.ROOT=DEBUG -Dlogging.level.io.github.jhipster=DEBUG -Dlogging.level.com.opti.ecom=DEBUG -Dlogging.path=/var/log/spring/ecom_v2/ -jar target/LatestBuild/ecom-0.0.1-SNAPSHOT.jar --spring.jpa.show_sql=true --spring.profiles.active=dev,no-liquibase --spring.datasource.url=jdbc:postgresql://aws_database_url --spring.datasource.username=user --spring.datasource.password=password --spring.datasource.hikari.maximum-pool-size=10
I have tried with the docker run --env
and the above individual args but it doesn’t work.
I don’t want to pass these args in the application.properties file.
Docker file:
FROM openjdk:11.0.7-jre-slim
ENV DEMO_ROOT=/root
ADD /target/LatestBuild/ecom-0.0.1-SNAPSHOT.jar $DEMO_ROOT
WORKDIR ${DEMO_ROOT}
CMD ["java", "-jar", "ecom-0.0.1-SNAPSHOT.jar"]
Would be glad to get some help on this.
Thanks!
2
Answers
A good practice is to use a configuration file that contains theses configuration properties (application.properties)
You can use a Docker file like this:
In the /conf volume, you should copy your application.properties
You can specify Spring properties as environment variables and particularly in a container setup this is much easier than trying to pass them as command-line arguments.
In a single
docker run
command you could writeGiven the number of settings, you may find it more convenient to put them in a dedicated file which you can pass to the
docker run --env-file
option.