Fix: Resolve permission issues with .storage directories
- Install su-exec in Dockerfile for user switching - Modified start.sh to create directories as root, then change ownership - Container starts as root but switches to nextjs user for app execution - This prevents permission denied errors when creating .storage directories
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -22,8 +22,8 @@ RUN pnpm build
|
||||
# Production stage
|
||||
FROM node:22-alpine AS production
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm ts-node
|
||||
# Install pnpm and su-exec
|
||||
RUN npm install -g pnpm ts-node && apk add --no-cache su-exec
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
@@ -53,9 +53,12 @@ RUN adduser -S nextjs -u 1001
|
||||
# Make start script executable
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
# Change ownership of the app directory
|
||||
# Change ownership of the app directory (but keep root for .storage)
|
||||
RUN chown -R nextjs:nodejs /app
|
||||
USER nextjs
|
||||
RUN chown root:root /app/.storage 2>/dev/null || true
|
||||
|
||||
# Don't switch to nextjs user here - the start script will handle it
|
||||
# USER nextjs
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
Reference in New Issue
Block a user