From c97167c7c2a995e8f3ce16f2fec3aaf3b2783eb8 Mon Sep 17 00:00:00 2001 From: Pauline Date: Sat, 28 Sep 2024 20:00:53 +0100 Subject: [PATCH] Fix Dockerfile due to permission issues with npm --- Dockerfile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 721ae7c..89417e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,29 @@ # LTS version of Node.js FROM node:20.9.0-alpine +# Create a new user and group for running the application +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + RUN mkdir -p /app WORKDIR /app COPY package*.json ./ -RUN npm install +# Change ownership of the app directory +RUN chown -R appuser:appgroup /app + +# Install npm dependencies as the non-root user +USER appuser + +# Clear npm cache and install dependencies +RUN npm cache clean --force && npm install -COPY . . +# Copy the rest of the application code +COPY --chown=appuser:appgroup . . RUN npm run build EXPOSE 3000 -# Start the app on port 4455 as recommended by ory CMD ["npm", "start", "--", "-p", "3000"]