// An highlighted block
#定义网络。
docker network create basenetwork --subnet=172.18.0.0/16
注意:MySQL配置文件my.cnf如下。
initdb文件夹中的是脚本是mysql容器启动后自动执行的脚本,可以放入nacos的数据库脚本,传送门nacos脚本。
// my.cnf
[mysqld]
user=mysql
character-set-server=utf8mb4
default-time-zone='+8:00'
port = 3306
user = mysql
bind-address = 0.0.0.0
server-id = 1
log_error = /var/log/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 3
slow_query_log_file = /var/log/mysql/mysql-slow.log
binlog_format = mixed
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
# docker-compose.yml
version: "3.9" # optional since v1.27.0
services:
mysql:
image: mysql:latest
#user: mysql:mysql
privileged: true
#network_mode: "host" # 如果需要容器使用宿主机IP(内网IP),则可以配置此项
hostname: mysql3306
container_name: mysql3306 # 指定容器名称,如果不设置此参数,则由系统自动生成
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci # 设置utf8字符集
entrypoint: bash -c "chown -R mysql:mysql /var/log/mysql && exec /entrypoint.sh mysqld"
environment:
- TZ=Asia/Shanghai # 设置容器时区与宿主机保持一致
- MYSQL_ROOT_PASSWORD=141535 # 设置root密码
volumes:
- /etc/timezone:/etc/timezone:ro
- ./mysql/mysql3306/data:/var/lib/mysql # 映射数据库保存目录到宿主机,防止数据丢失
- ./mysql/mysql3306/conf/my.cnf:/etc/my.cnf # 映射数据库配置文件
- ./mysql/mysql3306/logs:/var/log/mysql
- ./mysql/mysql3306/initdb:/docker-entrypoint-initdb.d # 需要初始化的数据库脚本存放文件夹,容器启动后会自动执行。
- ./mysql/mysql3306/script:/usr/local/mysql/script # 映射本地数据库脚本到容器,方便执行
ports:
- "3306:3306"
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.10
mongo:
image: mongo:latest
privileged: true
# restart: always
hostname: mongo27017
container_name: mongo27017
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/data/logs
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=141535
ports:
- 27017:27017 #对外暴露停供服务的端口,正式生产的时候理论不用暴露。
volumes:
- /etc/timezone:/etc/timezone:ro
- ./mongodb/mongo27017/data/db:/data/db # 挂载数据目录
- ./mongodb/mongo27017/log:/data/logs # 挂载日志目录
# - ./mongodb/config:/etc/mongo # 挂载配置目录
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.15
redis:
image: redis:latest
privileged: true
hostname: redis6379
container_name: redis6379
command: redis-server /etc/redis/redis.conf # 启动redis命令
environment:
- TZ=Asia/Shanghai
volumes:
- /etc/localtime:/etc/localtime:ro # 设置容器时区与宿主机保持一致
- ./redis/redis6379/data:/data
- ./redis/redis6379/conf/myredis.conf:/etc/redis/redis.conf
ports:
- "6379:6379"
networks:
basenetwork:
ipv4_address: 172.18.0.20
networks:
basenetwork:
external: true
注意:
如果nacos无法连接到MySQL(8.x),报错“no datasource set”,请使用navicat、datagrip、dbever等工具先连接到数据库再重启nacos容器。
server.base 为本机的host地址。
kafka容器依靠zookeeper
# docker-compose.yml
version: "3.9" # optional since v1.27.0
services:
rabbitmq:
image: rabbitmq:management
privileged: true
hostname: rabbitmq5672
container_name: rabbitmq5672
environment:
- TZ=Asia/Shanghai
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=141535
ports:
- "15672:15672"
- "5672:5672"
- "4369:4369"
- "25672:25672"
volumes:
- /etc/timezone:/etc/timezone:ro
- ./rabbitmq/rabbitmq5672/data:/var/lib/rabbitmq
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.50
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
nacos-server:
image: nacos/nacos-server:latest
privileged: true
hostname: nacos-server
container_name: nacos-server
environment:
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=mysql3306
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_DB_NAME=nacos_config
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=141535
- JVM_XMS=256m
- JVM_XMX=256m
- JVM_XMN=128m
ports:
- "8848:8848"
- "20880:20880"
- "20881:20881"
- "20882:20882"
volumes:
- /etc/timezone:/etc/timezone:ro
- ./nacos_server/nacos_server8848/logs:/home/nacos/logs
- ./nacos_server/nacos_server8848/data:/home/nacos/data
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.55
sentinel-dashboard:
image: bladex/sentinel-dashboard
privileged: true
container_name: sentinel
hostname: sentinel
ports:
- "8858:8858"
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.60
zookeeper:
image: wurstmeister/zookeeper
privileged: true
hostname: zookeeper2181
container_name: zookeeper2181
volumes:
- /etc/timezone:/etc/timezone:ro
- ./zookeeper/zookeeper2181/data:/data
- ./zookeeper/zookeeper2181/datalog:/datalog
- ./zookeeper/zookeeper2181/logs:/logs
ports:
- "2181:2181"
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.65
kafka:
image: wurstmeister/kafka
privileged: true
hostname: kafka9092
container_name: kafka9092
environment:
- KAFKA_BROKER_ID=0
- KAFKA_ZOOKEEPER_CONNECT=zookeeper2181:2181
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://server.base:9092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
ports:
- "9092:9092"
volumes:
- /etc/timezone:/etc/timezone:ro
- ./kafka/kafka9092:/kafka
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- zookeeper
# command: ["./wait-for.sh", "zookeeper:2181"]
#定义IP网络
networks:
basenetwork:
ipv4_address: 172.18.0.70
kafka-manager:
image: sheepkiller/kafka-manager
privileged: true
container_name: kafka-manager
hostname: kafka-manager
ports:
- 9000:9000
environment:
ZK_HOSTS: zookeeper2181:2181
networks:
basenetwork:
ipv4_address: 172.18.0.75
networks:
basenetwork:
external: true
# docker-compose.yml
version: "3.9" # optional since v1.27.0
services:
elasticsearch:
image: elasticsearch:7.14.1
privileged: true
hostname: elasticsearch9200
container_name: elasticsearch9200
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /etc/timezone:/etc/timezone:ro
- ./elasticsearch/elasticsearch9200/data:/usr/share/elasticsearch/data
- ./elasticsearch/elasticsearch9200/plugins:/usr/share/elasticsearch/plugins
ports:
- "9200:9200"
- "9300:9300"
networks:
basenetwork:
ipv4_address: 172.18.0.80
logstash:
image: logstash:7.14.1
privileged: true
hostname: logstash5044
container_name: logstash5044
volumes:
- ./logstash/logstash5044/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
ports:
- "5044:5044"
networks:
basenetwork:
ipv4_address: 172.18.0.85
kibana:
image: kibana:7.14.1
privileged: true
hostname: kibana5601
container_name: kibana5601
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch9200:9200
volumes:
- /etc/timezone:/etc/timezone:ro
ports:
- "5601:5601"
networks:
basenetwork:
ipv4_address: 172.18.0.90
networks:
basenetwork:
external: true