Hi i have created a spring boot application and want to add a non root user to in the docker file.
i was looking at the following https://spring.io/guides/topicals/spring-boot-docker/
and this command
RUN addgroup -S demo && adduser -S demo -G demo
USER demo
but this doesnt work in my docker file which is based on the followin image
FROM eclipse-temurin:17-focal
WORKDIR /app
COPY target/*.jar app.jar
EXPOSE 8080
RUN addgroup -S demo && adduser -S demo -G demo
USER demo
ENTRYPOINT ["java","-jar","/app.jar"]
Error:
error: failed to solve: process "/bin/sh -c addgroup -S app && adduser -S app -G app" did not complete successfully: exit code: 1
The image your are using inherits from an Ubuntu distribution, so you have use the right syntax for the failing commands.
You should change:
RUN addgroup -S demo && adduser -S demo -G demo
Into:
RUN addgroup demo
RUN useradd -g demo demo