I have my application.properties where I specified the path of my config file. I need to read this file during the runtime.
app.config = myApp/myConfig.conf
The file is in the root directory of my project. When I run my container, than my config file will not be found. How it is possible, that my container will find my config file by the path specified in my application.properties?
My dockerfile:
FROM eclipse-temurin:17.0.8.1_1-jre
COPY ./target/myApp.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
Build image:
docker build -t myApp:myApp .
Run docker:
docker run -p 8080:80 --name myAppContainer idOfImage
After executing docker run I got the error that myApp/myConfig.conf
could not be found
You should copy your config file myApp/myConfig.conf
into the image while building your image.
Example1: if your file structure:
Project Directory
-- Dockerfile
-- target
---- myApp.jar
-- myApp
---- myConfig.conf
Dockerfile (according to your file structure, copied .conf file path changes):
FROM eclipse-temurin:17.0.8.1_1-jre
COPY ./target/myApp.jar app.jar
COPY ./myApp/myConfig.conf ./myApp/myConfig.conf
ENTRYPOINT ["java", "-jar", "app.jar"]
Example2: if your file structure:
Project Directory
-- Dockerfile
-- target
---- myApp.jar
---- myApp
------- myConfig.conf
Dockerfile (according to your file structure, copied .conf file path changes):
FROM eclipse-temurin:17.0.8.1_1-jre
COPY ./target/myApp.jar app.jar
COPY ./target/myApp/myConfig.conf ./myApp/myConfig.conf
ENTRYPOINT ["java", "-jar", "app.jar"]