'Permission denied if Jar is trying to create a file

My-app.jar is has a piece of java code like below. While running the the docker image i am getting exception as FileNotFoundException with exception message as Permission Denied. Docker is new for me I need a quick resolution for the issue.

        String fileName = "cert.pem";
        File targetFile = new File("/cert_dir/"+ fileName);
        Files.write(buffer, targetFile);
# Start FROM Docker Image
FROM alpine
VOLUME /tmp

RUN adduser -u 10101 -D nonrootuser
USER 10101

# Add the application's jar to the container
COPY target/my-app.jar my-app.jar

ENV JVM_OPTS="-Xms1024m -Xmx4096m -XX:+AlwaysPreTouch -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:+ParallelRefProcEnabled -verbose:gc -XX:+PrintGCDetails -Xloggc:/tmp/my-app_gclog.log "

EXPOSE 8080
EXPOSE 8081

ENTRYPOINT java $JVM_OPTS -jar my-app.jar


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source