docker-compose.low-memory.yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. version: '3.8'
  2. services:
  3. # PostgreSQL 数据库 - 低内存优化配置
  4. postgres:
  5. image: postgres:15-alpine
  6. container_name: vue3-admin-postgres
  7. restart: unless-stopped
  8. environment:
  9. POSTGRES_DB: vue3_admin
  10. POSTGRES_USER: postgres
  11. POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-123456}
  12. # 低内存优化配置
  13. POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
  14. command: |
  15. postgres
  16. -c shared_buffers=64MB
  17. -c effective_cache_size=256MB
  18. -c maintenance_work_mem=32MB
  19. -c checkpoint_completion_target=0.9
  20. -c wal_buffers=4MB
  21. -c default_statistics_target=100
  22. -c random_page_cost=1.1
  23. -c effective_io_concurrency=200
  24. -c work_mem=2MB
  25. -c min_wal_size=1GB
  26. -c max_wal_size=2GB
  27. -c max_connections=50
  28. volumes:
  29. - postgres_data:/var/lib/postgresql/data
  30. - ./postgreSQL:/docker-entrypoint-initdb.d
  31. ports:
  32. - "5432:5432"
  33. networks:
  34. - vue3-admin-network
  35. healthcheck:
  36. test: ["CMD-SHELL", "pg_isready -U postgres"]
  37. interval: 30s
  38. timeout: 10s
  39. retries: 3
  40. # 资源限制
  41. deploy:
  42. resources:
  43. limits:
  44. memory: 512M
  45. cpus: '1.0'
  46. reservations:
  47. memory: 256M
  48. cpus: '0.3'
  49. # 主应用服务 - 低内存优化配置
  50. app:
  51. build:
  52. context: .
  53. dockerfile: Dockerfile
  54. container_name: vue3-admin-app
  55. restart: unless-stopped
  56. ports:
  57. - "80:80"
  58. - "6666:6666"
  59. environment:
  60. - NODE_ENV=production
  61. - NODE_OPTIONS=--max-old-space-size=512
  62. - DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD:-123456}@postgres:5432/vue3_admin
  63. - JWT_SECRET=${JWT_SECRET:-your-jwt-secret-key-here}
  64. - SESSION_SECRET=${SESSION_SECRET:-your-session-secret-key-here}
  65. volumes:
  66. - ./server/upload:/app/server/upload
  67. - app_logs:/app/logs
  68. depends_on:
  69. postgres:
  70. condition: service_healthy
  71. networks:
  72. - vue3-admin-network
  73. healthcheck:
  74. test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:6666/health"]
  75. interval: 45s
  76. timeout: 15s
  77. retries: 5
  78. start_period: 60s
  79. # 资源限制
  80. deploy:
  81. resources:
  82. limits:
  83. memory: 768M
  84. cpus: '1.5'
  85. reservations:
  86. memory: 384M
  87. cpus: '0.5'
  88. networks:
  89. vue3-admin-network:
  90. driver: bridge
  91. volumes:
  92. postgres_data:
  93. driver: local
  94. app_logs:
  95. driver: local