Docker Community Forums

Share and learn in the Docker community.

Docker build failure when changing permission from root to user


(Iadar) #1

Using this Dockerfile, I’m getting the following error… any help would be appreciated.
What am I doing wrong?

The Dockerfile:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8

# Run as non-root
RUN addgroup -g 1001 -S appuser && adduser -u 1001 -S appuser -G appuser
RUN mkdir /opt && chown -R appuser:appuser /opt/mycompany
RUN mkdir /logs && chown -R appuser:appuser /logs
USER appuser

EXPOSE 8080

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

The error:

Login Succeeded
+ gradle docker -Pregistry=****.net/**** -PmicroserviceName=**** -Ptag=0.0.125
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :bootJar UP-TO-DATE
> Task :dockerfileZip UP-TO-DATE
> Task :jar SKIPPED
> Task :assemble UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources UP-TO-DATE
> Task :testClasses UP-TO-DATE
> Task :test UP-TO-DATE
> Task :check UP-TO-DATE
> Task :build UP-TO-DATE
> Task :dockerClean
> Task :dockerPrepare

> Task :docker FAILED
The command '/bin/sh -c mkdir /opt && chown -R appuser:appuser /opt/mycompany' returned a non-zero code: 1

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':docker'.
> Process 'command 'docker'' finished with non-zero exit value 1

(Iadar) #2

Removing these two lines made the build step work, but the image itself is failing…

RUN mkdir /opt && chown -R appuser:appuser /opt/mycompany
RUN mkdir /logs && chown -R appuser:appuser /logs