diff --git a/Dockerfile b/Dockerfile index 0344c98..e41ba5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,8 @@ RUN npm run build # Production stage FROM node:20-alpine AS runner -# Install Python and yt-dlp dependencies -RUN apk add --no-cache python3 py3-pip ffmpeg +# Install Python, yt-dlp dependencies, and su-exec +RUN apk add --no-cache python3 py3-pip ffmpeg su-exec # Install yt-dlp RUN pip3 install --no-cache-dir yt-dlp --break-system-packages @@ -45,11 +45,19 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # Create data directory for database RUN mkdir -p /app/data && chown -R nextjs:nodejs /app -USER nextjs +# Switch to root to allow permission fixes on startup +USER root EXPOSE 3000 -ENV PORT 3000 -ENV HOSTNAME "0.0.0.0" +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" -CMD ["node", "server.js"] +# Create startup script that fixes permissions and starts the app +RUN echo '#!/bin/sh' > /start.sh && \ + echo 'mkdir -p /app/data' >> /start.sh && \ + echo 'chown -R nextjs:nodejs /app/data' >> /start.sh && \ + echo 'su-exec nextjs node server.js' >> /start.sh && \ + chmod +x /start.sh + +CMD ["/start.sh"]