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
2
Answers
The documented example uses an Alpine based image, whereas you’re using an Ubuntu-based image.
The thing about Alpine is that most commands come from BusyBox, and they don’t all follow the exact same syntax as "normal" Linux.
Running a docker build with your Dockerfile clearly shows that the syntax for
adduser/addgroup
is not recognised:TL;DR:
If you use
eclipse-temurin:17-jdk-alpine
as in your linked documentation, the image builds just fineThe image your are using inherited from an Ubuntu distribution, so you have use the right syntax for the failing commands.
You should change:
Into: