SubZeno
SubZeno

Reputation: 380

Permission error running a JAR as non-root user on Docker

I did write the following Dockerfiler:

FROM openjdk:8-jdk-alpine

RUN addgroup -g 999 -S appgroup && \
     adduser -u 999 -S appuser -G appgroup
USER appuser

COPY myapp.jar /usr/app/myapp.jar 

ENTRYPOINT ["java","-jar","/usr/app/myapp.jar"]  

When I run the image, I get the follwing error:

main ERROR Unable to create file logs/file.log java.io.IOException: Could not create directory /logs

Could you please tell me what I did wrong?

Upvotes: 0

Views: 2615

Answers (1)

norbjd
norbjd

Reputation: 11267

User appuser does not have write permissions in the current working directory (/, you can verify it with docker run --rm openjdk:8-jdk-alpine pwd), and it seems that your application needs to create a logs/ directory in that working directory.

Possible solutions :

  • set the WORKDIR to a place he can write (/tmp for example, or /home/appuser if it is created) in the Dockerfile
  • you can use option --workdir /path/to/a/folder/where/appuser/can/write when issuing docker run command
  • you can create the /logs folder with right permissions (write for appuser)

Upvotes: 4

Related Questions