I am new to this Dockerization part. I want to Dockerize the existing project. In this project we have multiple application.properties and Default.properties files which are not available in src/main/resources folder. While creating image it is working fine , but while running image it is throwing a error message like below. I tried by adding COPY option as well for application.properties file.
Please find below docker file data and error message i am receiving and let me know if i want to add more details.
@UPdating question
As i am moving properties file from local to /myapp/ I want to update my script to read external prop file. Here i am using below code , can someone guide me how to read file from docker contains using Java.
File[] files = null;
files = Paths.get(environment.getProperty("spring.config.location")).getParent().resolve(DATABASES).toFile()
.listFiles();
List of files.
/usr/app # ls env-prop services-testingtools.jar /usr/app # cd env-prop/ /usr/app/env-prop # ls local /usr/app/env-prop # cd local/Jlo /usr/app/env-prop/local # ls application.properties databases /usr/app/env-prop/local # cd databases/ /usr/app/env-prop/local/databases # ls DEFAULT.properties
Docker file :
FROM openjdk:8-jdk-alpine EXPOSE 3434 RUN mkdir /myapp ADD target/services-testingtools.jar /myapp/services-testingtools.jar ADD /env-prop/local/databases/DEFAULT.properties /myapp/DEFAULT.properties ADD /env-prop/local/application.properties /myapp/application.properties ENV spring.config.location=file:///myapp/DEFAULT-properties ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom --spring.config.location=file:///myapp/application-properties","-jar","/myapp/services-testingtools.jar"]
Error message.
2020-12-09 09:21:59.595 ERROR 1 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'tokenAuthorizationOncePerRequestFilter': Unsatisfied dependency expressed through field 'tokenUtil'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenUtil': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jwt.signing.key.secret' in value "${jwt.signing.key.secret}" 2020-12-09 09:21:59.627 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2020-12-09 09:21:59.677 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat 2020-12-09 09:21:59.695 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-12-09 09:21:59.703 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) ~[spring-boot-2.1.4.RELEASE.jar!/:2.1.4.RELEASE]