-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from bcgov/bug/node-root-user
Update Dockerfile
- Loading branch information
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
FROM docker.io/node:16.15.1-alpine | ||
|
||
# Set environment variable to avoid update notifications | ||
ENV NO_UPDATE_NOTIFIER=true | ||
|
||
# Set a custom npm cache directory | ||
ENV NPM_CONFIG_CACHE=/opt/app-root/src/app/.npm-cache | ||
|
||
# Set working directory | ||
WORKDIR /opt/app-root/src/app | ||
|
||
# Copy application source code and set ownership | ||
COPY . /opt/app-root/src | ||
|
||
# Create the npm cache directory and ensure the correct ownership | ||
RUN mkdir -p $NPM_CONFIG_CACHE && chown -R 1001:1001 /opt/app-root/src/app | ||
|
||
# Switch to a non-root user with UID and GID 1001 | ||
USER 1001:1001 | ||
|
||
# Install dependencies and build the application | ||
RUN npm run all:ci \ | ||
&& npm run all:build \ | ||
&& npm run client:purge | ||
&& npm run all:build \ | ||
&& npm run client:purge | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 8000 | ||
|
||
# Start the application | ||
CMD ["npm", "run", "start"] |