Skip to content

Commit feb5f1e

Browse files
use a non-root user in the container (#35)
* use a non-root user in the container * rename user and group to app
1 parent 265f6b4 commit feb5f1e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.github
2+
/.next
3+
/.env
4+
/node_modules

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ FROM node:20.18-alpine AS base
22
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
33
RUN apk add --no-cache libc6-compat vips
44
WORKDIR /opt/app
5+
# Create a non-root user and group
6+
RUN addgroup -g 10001 app \
7+
&& adduser -u 10000 -g app -S -h /home/app app \
8+
&& chown -R app:app /opt/app
9+
# Switch to the non-root user
10+
USER app:app
511

612
FROM base AS install
7-
COPY . .
8-
RUN npm install
13+
COPY --chown=app:app . .
14+
RUN chown -R app:app /opt/app \
15+
&& npm clean-install
916

1017
FROM install AS develop
1118
EXPOSE 3000

0 commit comments

Comments
 (0)