alexcdev1 5 months ago
parent
commit
7889dc1622
2 changed files with 3 additions and 6 deletions
  1. 2 4
      Dockerfile.prod
  2. 1 2
      docker-compose.prod.yml

+ 2 - 4
Dockerfile.prod

@@ -43,9 +43,8 @@ RUN apk add --no-cache bash
 # 创建非 root 用户
 RUN addgroup --system --gid 1001 nodejs
 RUN adduser --system --uid 1001 nextjs
-
 # 创建 uploads 目录并设置权限
-RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public
+RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public && chmod 755 /app/public/uploads
 
 # 复制必要文件
 COPY --from=builder /app/public ./public
@@ -62,5 +61,4 @@ EXPOSE 3000
 ENV PORT 3000
 
 # 使用 bash 启动应用
-# CMD ["/bin/bash", "-c", "node_modules/.bin/next start"]
-CMD ["/bin/bash", "-c", "chown -R nextjs:nodejs /app/public/uploads && su nextjs -c 'node_modules/.bin/next start'"]
+CMD ["/bin/bash", "-c", "node_modules/.bin/next start"]

+ 1 - 2
docker-compose.prod.yml

@@ -16,8 +16,7 @@ services:
     restart: unless-stopped  # 添加自动重启策略
     volumes:
       - nextjs-uploads:/app/public/uploads  # 添加这行来挂载 uploads volume
-    user: root
-    
+
   mongodb:
     image: mongo
     volumes: