Browse Source

修复上传图片

alexcdev1 5 months ago
parent
commit
854e629ecd
3 changed files with 9 additions and 36 deletions
  1. 2 0
      .gitignore
  2. 3 0
      Dockerfile.prod
  3. 4 36
      docker-compose.prod.yml

+ 2 - 0
.gitignore

@@ -34,3 +34,5 @@ yarn-error.log*
 # typescript
 *.tsbuildinfo
 next-env.d.ts
+
+public/uploads

+ 3 - 0
Dockerfile.prod

@@ -44,6 +44,9 @@ RUN apk add --no-cache bash
 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
+
 # 复制必要文件
 COPY --from=builder /app/public ./public
 COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next

+ 4 - 36
docker-compose.prod.yml

@@ -1,39 +1,3 @@
-# version: '3'
-
-# services:
-#   nextjs:
-#     build:
-#       context: .
-#       dockerfile: Dockerfile.prod
-#       args:
-#         - MONGODB_URI=mongodb://mongodb:27017/mydatabase
-#     ports:
-#       - "3000:3000"
-#     environment:
-#       - NODE_ENV=production
-#       - MONGODB_URI=mongodb://mongodb:27017/mydatabase
-#     depends_on:
-#       - mongodb
-
-#   mongodb:
-#     image: mongo
-#     volumes:
-#       - mongodb_data:/data/db
-
-#   nginx:
-#     image: nginx:alpine
-#     ports:
-#       - "8088:80"
-#     volumes:
-#       - ./nginx:/etc/nginx/conf.d
-#       - ./logs/nginx:/var/log/nginx
-
-#     depends_on:
-#       - nextjs
-
-# volumes:
-#   mongodb_data:
-
 services:
   nextjs:
     container_name: match-vote-nextjs-nextjs-1 
@@ -50,6 +14,9 @@ services:
     depends_on:
       - mongodb
     restart: unless-stopped  # 添加自动重启策略
+    volumes:
+      - nextjs-uploads:/app/public/uploads  # 添加这行来挂载 uploads volume
+
 
   mongodb:
     image: mongo
@@ -70,6 +37,7 @@ services:
 
 volumes:
   mongodb_data:
+  nextjs-uploads:
 
 networks:
   default: