docker-compose.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. version: "3.9"
  2. # Docker for Ubuntu22.04 configuration
  3. # - mysql 8.0.23
  4. # - redis 6.2
  5. # -- 配置 -----------------------------
  6. # docker-compose down
  7. # docker-compose up -d
  8. # 1.首次启动前创建 (MySQL)
  9. # mkdir -p /opt/mysql/{data,config} /opt/mysql-files
  10. # chmod -R 777 /opt/mysql
  11. # 拷贝 my.cnf 配置文件 (MySQL)
  12. # * 首次启动,不要带 my.cnf 映射,要先把 my.cnf 文件拷出来
  13. # docker cp mysql8:/etc/mysql/my.cnf /opt/mysql/config
  14. # chmod 644 /opt/mysql/config/my.cnf
  15. # (保证 my.cnf 必须是文件,不是目录)
  16. # 3.首次启动前创建(Redis)
  17. # mkdir -p /opt/redis/{data,logs}
  18. # chmod -R 777 /opt/redis
  19. # 4.首次启动前创建(Nginx)
  20. # mkdir -p /opt/nginx/{www,log}
  21. # chmod -R 777 /opt/nginx
  22. # 拷贝 nginx.conf 配置文件 (Nginx)
  23. # docker cp nginx:/etc/nginx/conf.d /opt/nginx
  24. # docker cp nginx:/etc/nginx/nginx.conf /opt/nginx/nginx.conf
  25. # docker cp nginx:/usr/share/nginx/html /opt/nginx/www/html
  26. # -------------------------------------
  27. services:
  28. # -- MySQL8.0 -----------------------
  29. mysql8:
  30. image: mysql:8.0.23
  31. container_name: mysql8
  32. restart: always
  33. environment:
  34. MYSQL_ROOT_PASSWORD: fiPxHGFJldDC
  35. ports:
  36. - "3306:3306"
  37. volumes:
  38. - /opt/mysql/data:/var/lib/mysql
  39. # 首次复制 (docker cp)
  40. # - /opt/mysql/config/my.cnf:/etc/mysql/my.cnf:ro
  41. - /opt/mysql-files:/var/lib/mysql-files
  42. command:
  43. - mysqld
  44. - --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  45. # -- Redis6.2 -----------------------
  46. redis:
  47. image: redis:6.2 # 官方完整版,非 Alpine
  48. container_name: redis62
  49. restart: always
  50. ports:
  51. - "127.0.0.1:6388:6388" # 仅宿主机 127.0.0.1:6388 可访问
  52. volumes:
  53. - /opt/redis/data:/data # 数据持久化
  54. - /opt/redis/logs:/logs # 日志外挂
  55. environment:
  56. - TZ=UTC # UTC时区 (国内时区: Asia/Shanghai)
  57. command: >
  58. redis-server
  59. --port 6388
  60. --bind 127.0.0.1
  61. --requirepass 123456
  62. --appendonly yes
  63. --loglevel warning
  64. --logfile /logs/redis.log
  65. # -- Nginx --------------------------
  66. nginx:
  67. image: nginx:1.26.3
  68. container_name: nginx
  69. restart: always
  70. ports:
  71. - "80:80"
  72. - "443:443"
  73. volumes:
  74. # 首次复制 (docker cp)
  75. # - /opt/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
  76. # - /opt/nginx/www/html:/usr/share/nginx/html:ro
  77. # - /opt/nginx/conf.d:/etc/nginx/conf.d:ro
  78. - /opt/nginx/log:/var/log/nginx
  79. environment:
  80. - TZ=UTC