DockerCompose 安装环境

avatar
作者
猴君
阅读量:0

1. Redis

version: '3' services:   redis:     image: redis:6.2.12     container_name: redis     ports:       - "6379:6379"     environment:       TZ: Asia/Shanghai     volumes:       # 本地数据目录要先执行 chmod 777 /usr/local/docker/redis/data 赋予读写权限,否则将无法写入数据       - /usr/local/docker/redis/conf:/redis/config:rw       - /usr/local/docker/redis/data/:/redis/data/:rw     command: ["redis-server", "/redis/config/redis.conf"]     # 容器开机自启     restart: always     # 获取宿主机 root 权限     privileged: true     # 设置容器网络为本机网络     network_mode: "host" 

2. Mysql

version: '3' services:   mysql:     image: mysql:8.0.33     container_name: mysql     environment:       TZ: Asia/Shanghai       MYSQL_ROOT_PASSWORD: root     ports:       - "3306:3306"     volumes:       # 数据挂载       - /usr/local/docker/mysql/data/:/var/lib/mysql/       # 配置挂载       - /usr/local/docker/mysql/conf/:/etc/mysql/conf.d/     command:       # 将 mysql8.0 默认密码策略修改为原先策略 (mysql8.0对其默认策略做了更改,会导致密码无法匹配)       --default-authentication-plugin=mysql_native_password       --character-set-server=utf8mb4       --collation-server=utf8mb4_general_ci       --explicit_defaults_for_timestamp=true       --lower_case_table_names=1     privileged: true     network_mode: "host" 

3. Nginx

version: '3' services:   nginx:     image: nginx:1.23.4     container_name: nginx-web     environment:       TZ: Asia/Shanghai     ports:       - "80:80"       - "443:443"     volumes:       # 配置文件映射       - /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf       # 页面目录       - /usr/local/docker/nginx/html:/usr/share/nginx/html       # 日志目录       - /usr/local/docker/nginx/log:/var/log/nginx     privileged: true     network_mode: "host" 

nginx.conf

# 工作进程数,通常设为 CPU 核心数 worker_processes 1;  # 错误日志路径 error_log /var/log/nginx/error.log warn;  # 存放 nginx 进程ID 的文件 pid /var/run/nginx.pid;  # 设置每个 worker 进程的最大连接数为1024 events {    worker_connections 1024; }  http { 	# 文件扩展名与文件类型映射表     include /etc/nginx/mime.types; 	# 默认文件类型     default_type application/octet-stream; 	# 开启高效文件传输模式     sendfile on; 	# 连接保持超时时间     keepalive_timeout 65; 	# 限制 body 大小     client_max_body_size 100m; 	# 日志格式     log_format main '$remote_addr - $remote_user [$time_local] "$request" '                     '$status $body_bytes_sent "$http_referer" '                     '"$http_user_agent" "$http_x_forwarded_for"'; 	# 访问日志路径及格式     access_log var/log/nginx/access.log main; 	 	# 定义一个服务器组,配置负载均衡策略     upstream server {         ip_hash;         server 192.168.1.1:8080; 		server 192.168.1.2:8080; 		server 192.168.1.3:8080;     }          # 配置 admin 服务,没有删除此配置     upstream cnbai-admin {         server 192.168.1.1:8888;     }          # 配置 web 服务,没有删除此配置     upstream cnbai-web {         ip_hash;         server 192.168.1.1:9999;         server 192.168.1.2:9999;     }  	# 配置虚拟主机     server { 		# 监听端口         listen 80; 		# 服务器名称,可以是域名或IP         server_name localhost;  		# 配置前端映射         location / { 			# docker映射路径             root /usr/share/nginx/html;             # 文件校验不存在就前往首页             try_files $uri $uri/ /index.html;             index index.html index.htm;         }  		# 配置后端映射         location /api/ {             proxy_pass http://server/;             proxy_set_header Host $host;             proxy_set_header X-Real-IP $remote_addr;             proxy_set_header REMOTE-HOST $remote_addr;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 			# websocket 参数,没有删除此配置             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection "upgrade";         }                  # 配置 admin 映射,没有删除此配置         location /admin/ {             proxy_set_header Host $http_host;             proxy_set_header X-Real-IP $remote_addr;             proxy_set_header REMOTE-HOST $remote_addr;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_pass http://cnbai-admin/admin/;         }          # 配置 web 映射,没有删除此配置         location /web/ {             proxy_set_header Host $http_host;             proxy_set_header X-Real-IP $remote_addr;             proxy_set_header REMOTE-HOST $remote_addr;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_pass http://cnbai-web/web/;         }  		# 配置后端虚拟路径映射,没有删除此配置 		location /upload/ { 			proxy_pass http://server/upload/; 			proxy_set_header Host $host; 			proxy_set_header X-Real-IP $remote_addr; 			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 			proxy_set_header X-Forwarded-Proto $scheme; 		} 	 		# 自定义404页面 		error_page 404 /404.html;  			location = /40x.html { 		} 	 		# 自定义50x错误页面 		error_page 500 502 503 504 /50x.html;  			location = /50x.html { 		}     } } 

4. Minio

version: '3' services:   minio:     image: minio/minio:RELEASE.2023-04-13T03-08-07Z     container_name: minio     ports:       # api 端口       - "9000:9000"       # 控制台端口       - "9001:9001"     environment:       TZ: Asia/Shanghai       # 管理后台用户名       MINIO_ROOT_USER: cnbai       # 管理后台密码,最小8个字符       MINIO_ROOT_PASSWORD: 12345678       # https需要指定域名       # MINIO_SERVER_URL: "https://xxx.com:9000"       # MINIO_BROWSER_REDIRECT_URL: "https://xxx.com:9001"       # 开启压缩 on 开启 off 关闭       MINIO_COMPRESS: "off"       # 扩展名 .pdf,.doc 为空 所有类型均压缩       MINIO_COMPRESS_EXTENSIONS: ""       # mime 类型 application/pdf 为空 所有类型均压缩       MINIO_COMPRESS_MIME_TYPES: ""     volumes:       # 映射文件目录       - /usr/local/docker/minio/data:/data       # 映射配置目录       - /usr/local/docker/minio/config:/root/.minio/     # 指定容器中的目录 /data     command: server --address ':9000' --console-address ':9001' /data     privileged: true     network_mode: "host" 

5. Jar 服务

version: '3' services:   app:     image: app:1.0     container_name: app     environment:       TZ: Asia/Shanghai       SERVER_PORT: 8080     volumes:       - /usr/local/docker/app/logs/:/app/logs/       - /usr/local/docker/app/config/:/app/config/     restart: always     privileged: true     network_mode: "host"    cnbai-admin:     image: cnbai-admin:1.0     container_name: cnbai-admin     environment:       TZ: Asia/Shanghai       SERVER_PORT: 8888     volumes:       - /usr/local/docker/admin/logs/:/admin/logs/       - /usr/local/docker/admin/config/:/admin/config/     restart: always     privileged: true     network_mode: "host"    cnbai-web:     image: cnbai-web:1.0     container_name: cnbai-web     environment:       TZ: Asia/Shanghai       SERVER_PORT: 9999     volumes:       - /usr/local/docker/web/logs/:/web/logs/       - /usr/local/docker/web/config/:/web/config/     restart: always     privileged: true     network_mode: "host" 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!