Correct file permissions for non-root user in Docker

This commit is contained in:
2025-10-13 18:44:55 +02:00
parent bd65177a25
commit 632ef4c812

View File

@@ -32,15 +32,22 @@ FROM base AS production
# Set a non-root user for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# Copy only the necessary files from the previous stages
COPY --from=build /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/views ./views
COPY --from=build /usr/src/app/static ./static
COPY --from=build /usr/src/app/lib ./lib
COPY --from=build /usr/src/app/server.js .
COPY --from=build /usr/src/app/config.json .
# Create the data directory and set correct permissions
# This is the FIX for the EACCES error
RUN mkdir -p data && chown -R appuser:appgroup .
# Switch to the non-root user
USER appuser
# Expose the port the app runs on
EXPOSE 8080