My app works fine from the IDE. But when I docarize the app, it can't find the applicaiton resoruce. How to docarize the app correctly that I can access resocur folder. Here is my code:-
Dockerfile
FROM eclipse-temurin:17-jre-alpine
RUN mkdir -p /app
COPY target/Toolkit-*.jar /app/toolkit.jar
WORKDIR /app/
ENTRYPOINT java -jar toolkit.jar
I am reading propety as this:
@Log
public class PropertyLoader {
private static String RESOURCE_FILENAME = "application.properties";
private static PropertyLoader instance;
private Properties properties;
private PropertyLoader() {
// works fine form IDE. Docker inputStream is null
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(RESOURCE_FILENAME)) {
properties = new Properties();
properties.load(inputStream);
} catch (IOException e) {
log.log(Level.SEVERE, e.getMessage());
}
}
}
How do I read application resorces in docker continaer?
You need to add application.properties to the image as well. add this to your Dockerfile
RUN mkdir -p /app/config
COPY <your file> /app/config/application.properties