alexcdev1 5 months ago
parent
commit
5103a94381
2 changed files with 10 additions and 2 deletions
  1. 2 1
      Dockerfile.prod
  2. 8 1
      docker-compose.prod.yml

+ 2 - 1
Dockerfile.prod

@@ -62,4 +62,5 @@ EXPOSE 3000
 ENV PORT 3000
 
 # 使用 bash 启动应用
-CMD ["/bin/bash", "-c", "node_modules/.bin/next start"]
+# 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'"]

+ 8 - 1
docker-compose.prod.yml

@@ -13,10 +13,17 @@ services:
       - MONGODB_URI=mongodb://mongodb:27017/mydatabase
     depends_on:
       - mongodb
+      - init-uploads
     restart: unless-stopped  # 添加自动重启策略
     volumes:
       - nextjs-uploads:/app/public/uploads  # 添加这行来挂载 uploads volume
-
+  
+  init-uploads:
+    image: alpine
+    volumes:
+      - nextjs-uploads:/uploads
+    command: chown -R 1001:1001 /uploads
+    user: root
 
   mongodb:
     image: mongo