0

While running a java code in a docker container with root user, getting permission denied error.

Java Code

File f = new File("example.xlsx");
f.createNewFile(); // error at this line

Error:

ava.io.IOException: Permission denied
    at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:na]
    at java.base/java.io.File.createNewFile(File.java:1035) ~[na:na]

The docker image created with the docker file

FROM docker:dind
USER root
RUN apk add curl maven openjdk11
RUN wget https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.10.0/allure-commandline-2.10.0.zip
RUN unzip allure-commandline-2.10.0.zip -d /
RUN export PATH="${PATH}:/allure-2.10.0/bin"

and container created using command

docker run -d -p 8080:8080 --add-host="dockerhost:${DOCKERHOST_IP}"
      -e parameter
      --name app ${CI_REGISTRY_IMAGE}:${CI_PIPELINE_ID}
  • 1
    The userID under which your program is running does not have write access to the "current directory" of the process. You should be using absolute paths or explicitly set the current directory to a known good location before attempting to create a file in this way. – Jim Garrison Apr 27 '22 at 17:08
  • Please share what kind of OS the image is created from. Is it Ubuntu container? Alpine Linux container? Windows container? MacOS container etc? Can you share a little bit more about how you made this container? I ask because usually this happens to me not bc of my code, but because of something about my container setup. Perhaps I can help with more info. – sitting-duck Apr 27 '22 at 18:01

0 Answers0