From fc5fb63f03a5f59909a45ad2a6645dc56cb4f719 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Mon, 5 Feb 2024 11:23:14 +0100 Subject: [PATCH] update Dockerfile to specific version and use of nonroot user (#266) * using alpine specific version instead of latest * running container with nonroot user --- Dockerfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 055369e..d4f692b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,12 @@ COPY src/ . RUN CGO_ENABLED=0 go build -ldflags="-w -s -X 'main.apiVersion=${apiVersion}'" -o app ./... -# get latest alpine container -FROM alpine:latest +# get alpine container +FROM alpine:alpine:3.19.1 + +# create nonroot user +RUN addgroup -S nonroot \ + && adduser -S nonroot -G nonroot # add ca-certificates RUN apk --no-cache add ca-certificates tzdata @@ -32,6 +36,9 @@ WORKDIR /root/ # copy binary from first container COPY --from=0 /go/src/app . +# set user +USER nonroot + # expose port 8080 EXPOSE 8080