修改镜像文件

This commit is contained in:
Vaica committed 2026-06-21 22:30:54 +08:00
1 parent d1716bf2ec
commit a43d9333b5
2 files changed
+21 -8

No files matched your search

+9 -8
View File
@@ -32,8 +32,8 @@ RUN npm run build
FROM node:20-alpine AS runner FROM node:20-alpine AS runner
WORKDIR /app WORKDIR /app
# Install Hugo # Install Hugo and su-exec (for entrypoint)
RUN apk add --no-cache hugo RUN apk add --no-cache hugo su-exec
# Create non-root user # Create non-root user
RUN addgroup --system --gid 1001 nodejs && \ RUN addgroup --system --gid 1001 nodejs && \
@@ -47,12 +47,12 @@ COPY --from=builder /app/.next/static ./.next/static
# Copy package.json for version info # Copy package.json for version info
COPY --from=builder /app/package.json ./ COPY --from=builder /app/package.json ./
# Create necessary directories # Copy entrypoint script
RUN mkdir -p /app/logs /app/backups && \ COPY entrypoint.sh /entrypoint.sh
chown -R nextjs:nodejs /app RUN chmod +x /entrypoint.sh
# Switch to non-root user # Create necessary directories
USER nextjs RUN mkdir -p /app/logs /app/backups /app/recycle/posts /app/recycle/meta
# Expose port # Expose port
EXPOSE 8016 EXPOSE 8016
@@ -66,5 +66,6 @@ ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8016/api/stats || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:8016/api/stats || exit 1
# Start application # Start application via entrypoint (fixes permissions, drops to nextjs)
ENTRYPOINT ["/entrypoint.sh"]
CMD ["node", "server.js"] CMD ["node", "server.js"]
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
# Docker entrypoint script
# 修复挂载目录权限后以 nextjs 用户启动应用
# 创建必要的子目录(以 root 身份)
mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
# 修复权限
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
# 以 nextjs 用户启动应用
exec su-exec nextjs "$@"