diff --git a/Dockerfile b/Dockerfile index b2a8cde..7fb9763 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ && rm -rf /var/lib/apt/lists/* \ && groupadd --system --gid 1001 nodejs \ - && useradd --system --uid 1001 nextjs + && useradd --system --uid 1001 nextjs \ + && mkdir -p /home/nextjs && chown nextjs:nextjs /home/nextjs COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ @@ -52,6 +53,9 @@ COPY --from=builder /app/prisma/schema.prisma /app/schema.prisma COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# Create data directory and initialize database as root +RUN mkdir -p /app/data && chown -R nextjs:nodejs /app + USER nextjs EXPOSE 3000 @@ -59,6 +63,7 @@ EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" ENV DATABASE_URL="file:./data/dev.db" +ENV HOME=/home/nextjs ENTRYPOINT ["docker-entrypoint.sh"] CMD ["node", "server.js"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 32dd391..e36db27 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,11 +4,12 @@ set -e # Initialize database if it doesn't exist or schema changed echo "Checking database..." -# Create data directory if it doesn't exist +# Create directories with proper permissions mkdir -p /app/data +mkdir -p /app/.npm # Push schema (safe - won't overwrite data, only syncs schema) -npx prisma db push --skip-generate --skip-pull +npm exec -- prisma db push --skip-generate --skip-pull echo "Starting application..." exec "$@"