From c4e6438ace0ee6241b5bd6dbc2ffeacc87d22f07 Mon Sep 17 00:00:00 2001 From: Peter Karolyi Date: Fri, 3 May 2024 13:32:42 +0200 Subject: [PATCH] feat: run as non-root user --- Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2079512..00b968f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,18 +20,24 @@ RUN pnpm build FROM base AS runner +# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user +RUN deluser --remove-home node && addgroup -S node -g 1000 && adduser -S -G node -u 1000 node + # https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals RUN apk --no-cache add tini WORKDIR /garden-snail -COPY package.json pnpm-lock.yaml ./ +RUN chown -R node:node . +COPY --chown=node:node package.json pnpm-lock.yaml ./ # with NODE_ENV=production pnpm will not install devDependencies ENV NODE_ENV=production RUN pnpm install --frozen-lockfile -COPY --from=builder /garden-snail/dist ./dist +COPY --from=builder --chown=node:node /garden-snail/dist ./dist + +USER node EXPOSE 3000 ENTRYPOINT ["/sbin/tini", "node", "dist/main"]