Skip to content

Commit bbbcd09

Browse files
committed
🐳 refactor to add user
1 parent 4f4f996 commit bbbcd09

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Dockerfile

+19-10
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,31 @@ FROM node:16.13.2-alpine
3131
ENV PORT=80 \
3232
DIRECTORY=/app \
3333
IS_DOCKER=true \
34-
UID=1000 \
35-
GUID=1000
34+
USER=docker \
35+
UID=12345 \
36+
GID=23456
3637

37-
# Create a group and user
38-
RUN addgroup --gid ${GUID} application \
39-
&& adduser --no-create-home --uid ${UID} application application
38+
# Install tini for initialization and tzdata for setting timezone
39+
RUN apk add --no-cache tzdata tini \
40+
# Add group
41+
&& addgroup --gid ${GID} "${USER}" \
42+
# Add user
43+
&& adduser \
44+
--disabled-password \
45+
--ingroup "${USER}" \
46+
--gecos "" \
47+
--home "${DIRECTORY}" \
48+
--no-create-home \
49+
--uid "$UID" \
50+
"$USER"
51+
52+
USER ${USER}
4053

41-
USER application
4254
# Create and set the working directory
4355
WORKDIR ${DIRECTORY}
4456

45-
# Install tini for initialization and tzdata for setting timezone
46-
RUN apk add --no-cache tzdata tini
47-
4857
# Copy built application from build phase
49-
COPY --from=BUILD_IMAGE /app ./
58+
COPY --from=BUILD_IMAGE --chown=${USER}:${USER} /app ./
5059

5160
# Finally, run start command to serve up the built application
5261
ENTRYPOINT [ "/sbin/tini", "--" ]

0 commit comments

Comments
 (0)