Docker Community Forums

Share and learn in the Docker community.

Running build as non root user

Hi everyone. New here, was wondering if someone had experience with building images as non root user?

I am building kotlin project, (2 step build) and my goal is now to build it as non root user. Here is what my Dockerfile looks like. Any help would be appreciated:

# Build
FROM openjdk:11-jdk-slim as builder

# Compile application
COPY . .
RUN ./gradlew build

FROM openjdk:11-jre-slim

# Add application
COPY --from=builder /root/build/libs/*.jar ./app.jar

# Set the build version
ARG build_version
ENV BUILD_VERSION=$build_version

RUN chmod 777 /

By default that Unix socket is owned by the user root and other users can only access it using sudo . The Docker daemon always runs as the root user. If you don’t want to preface the docker command with sudo , create a Unix group called docker and add users to it.