使用时
Ctrl+F
搜索你想要的环境,如果没有你想要的环境,可以评论留言,会尽力补充。本文提供的部署脚本默认参数仅适合开发测试,请根据实际情况调节参数。
数据库
MySQL
yml
version: '3.9'
services:
mysql:
image: 'mysql:8.0.35'
container_name: mysql-server
restart: always
command: '--default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci'
environment:
- MYSQL_ROOT_PASSWORD=lY4iQ}8":zK5
ports:
- "3306:3306"
volumes:
- 'mysql_data:/var/lib/mysql'
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
volumes:
mysql_data:
PostgreSQL (PGSQL)
yml
version: '3.9'
services:
postgres:
image: 'postgres:14'
container_name: postgresql
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=etRu)7E3!#O8
ports:
- "5432:5432"
volumes:
- 'postgres_data:/var/lib/postgresql/data'
deploy:
resources:
limits:
memory: 512M
volumes:
postgres_data:
SQL Server (MSSQL)
yml
version: '3.9'
services:
mssql:
image: 'mcr.microsoft.com/mssql/server:2022-latest'
restart: always
ports:
- '1433:1433'
environment:
- MSSQL_SA_PASSWORD=Zu.d8>;8IJ7l
- ACCEPT_EULA=Y
volumes:
- 'mssql_data:/var/opt/mssql/data'
deploy:
resources:
limits:
memory: 2048M
volumes:
mssql_data:
Redis
简易配置
# redis.conf
# 设置最大使用内存为 512MB (默认为全部可用物理内存)
maxmemory 536870912
# 使用 Unix Domain Socket,比 TCP/IP 更快
unixsocket /tmp/redis.sock
# 设置 Redis 服务器监听端口号
port 6379
# 设置 Redis 所使用的数据库数量,默认为 16 个
databases 16
# 不限制访问来源
bind 0.0.0.0
# 设置 Redis 密码
requirepass 8*%u3Td#oV!yD9L7
docker-compose
yml
version: '3.9'
services:
redis:
command: 'redis-server /etc/redis/redis.conf'
image: 'redis:7.2.3-alpine'
container_name: redis
volumes:
- 'redis_data:/data/redis'
- './conf/redis.conf:/etc/redis/redis.conf'
ports:
- '6379:6379'
restart: always
tty: true
stdin_open: true
deploy:
resources:
limits:
memory: 512M
volumes:
redis_data:
Elasticsearch (es)
配置文件
yml
# elasticsearch.yml
cluster.name: es
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
docker-compose
yml
version: '3.9'
services:
elasticsearch:
image: 'elasticsearch:7.17.3'
container_name: elasticsearch
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
cap_add:
- IPC_LOCK
mem_limit: 1g
environment:
- discovery.type=single-node
volumes:
- 'es_data:/usr/share/elasticsearch/data'
- './config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml'
ports:
- '9200:9200'
- '9300:9300'
deploy:
resources:
limits:
memory: 512M
volumes:
es_data:
消息队列
RabbitMQ
yml
version: '3'
services:
mq:
image: 'rabbitmq:3.9-management'
container_name: rabbitmq
hostname: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
volumes:
- 'rabbitmq_data:/var/lib/rabbitmq'
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
deploy:
resources:
limits:
memory: 512M
volumes:
rabbitmq_data:
RocketMQ
yml
version: '3.9'
services:
# https://hub.docker.com/r/xuchengen/rocketmq
# 注意修改项;
# 01:data/rocketmq/conf/broker.conf 添加 brokerIP1=127.0.0.1
# 02:data/console/config/application.properties server.port=9009 - 如果8080端口被占用,可以修改或者添加映射端口
rocketmq:
image: livinphp/rocketmq:5.1.0
container_name: rocketmq
ports:
- 8080:8080
- 9876:9876
- 10909:10909
- 10911:10911
- 10912:10912
volumes:
- ./data:/home/app/data
environment:
TZ: "Asia/Shanghai"
NAMESRV_ADDR: "rocketmq:9876"
对象存储
MinIO
yml
version: '3.9'
services:
minio:
command: 'server /data --console-address ":9001"'
restart: always
image: quay.io/minio/minio
container_name: minio
environment:
- MINIO_ROOT_USER=minio
- MINIO_ROOT_PASSWORD=miniopwd
volumes:
- 'minio_data:/data'
ports:
- '9001:9001'
- '9000:9000'
deploy:
resources:
limits:
memory: 512M
volumes:
minio_data:
Spring Cloud Alibaba
Nacos
yml
version: '3.9'
services:
nacos:
image: nacos/nacos-server:v2.2.0-slim
container_name: nacos
ports:
- "8848:8848"
environment:
- PREFER_HOST_MODE=hostname
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=mysql
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_DB_NAME=nacos_config
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=password
deploy:
resources:
limits:
memory: 1024M
depends_on:
- mysql
mysql:
image: mysql:5.7
container_name: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=nacos_config
volumes:
- 'mysql_data:/var/lib/mysql'
deploy:
resources:
limits:
memory: 256M
volumes:
mysql_data:
使用自建数据库将mysql
模块删除,并将Nacos数据库连接信息替换成目标数据库说明:
说明:
- 使用
nacos/nacos-server:v2.2.0-slim
镜像启动 Nacos 服务,v2.2.0-slim
可替换为指定版本。 - 映射容器的
8848
端口到主机的8848
端口,使其可通过localhost:8848
访问。 - 设置了多个环境变量来连接 MySQL 数据库:
MODE=standalone
:指定 Nacos 以单机模式运行。SPRING_DATASOURCE_PLATFORM=mysql
:告诉 Nacos 使用 MySQL 作为数据源。MYSQL_SERVICE_HOST=mysql
:指定 MySQL 服务的主机名,这里与 MySQL 服务的容器名称相对应。MYSQL_SERVICE_PORT=3306
:MySQL 服务的端口号。MYSQL_SERVICE_DB_NAME=nacos_config
:用于存储 Nacos 数据的数据库名称。MYSQL_SERVICE_USER=root
和MYSQL_SERVICE_PASSWORD=password
:MySQL 的用户名和密码。