Skip to content

Commit 47b5ac3

Browse files
authored
chore: Use non-root user in Docker container by default (#103)
This applies best-practices as described in * https://cheatsheetseries.owasp.org/cheatsheets/NodeJS_Docker_Cheat_Sheet.html * https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
1 parent 3793554 commit 47b5ac3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ FROM node:22.17.1-alpine3.21
1919
WORKDIR /app
2020

2121
# Copy package files and install production dependencies
22-
COPY --from=build /app/package.json /app/package-lock.json /app/
22+
COPY --from=build --chown=node:node /app/package.json /app/package-lock.json /app/
2323
RUN npm ci --only=production --ignore-scripts && npm cache clean --force
2424

2525
# Copy the built application
26-
COPY --from=build /app/dist /app/dist
26+
COPY --from=build --chown=node:node /app/dist /app/dist
27+
28+
# Run image as non-root user
29+
USER node
2730

2831
# Start the application
2932
CMD ["node", "dist/index.js"]

0 commit comments

Comments
 (0)