I had a working dockerfile, but I wanted to upgrade it so that the container would not run from the root user. Here is the initial version of the dockerfile:
FROM something/openjdk-17:1.13-1
WORKDIR /opt/app
COPY ./build/libs/*.jar app.jar
CMD java ${JAVA_OPTS:- -Xmx1G} -jar app.jar
Then, I tried to add a user, grant him rights and run the container on his behalf.
FROM something/openjdk-17:1.13-1
RUN adduser -D trmonbs && chown -R trmonbs /opt/app
WORKDIR /opt/app
COPY ./build/libs/*.jar app.jar
USER trmonbs
CMD java ${JAVA_OPTS:- -Xmx1G} -jar app.jar
However, I got:
The command '/bin/sh -c adduser -D trmonbs && chown -R trmonbs /opt/app' returned a non-zero code: 2
Process exited with code 2
What could be the problem?