一、文件docker-compose配置文件
version: "3"
services:
redis:
image: redis:5.0.9
container_name: c-fds-redis
ports:
- "6379:6379"
volumes:
- /home/dockerHome/redis/redis.conf:/etc/redis/redis.conf
- /home/dockerHome/redis/data:/data
mysql:
build:
context: ./db
image: i-fds-mysql:5.7.31
container_name: c-fds-mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_USER: 'root'
MYSQL_PASS: '123456'
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
volumes:
- /home/dockerHome/mysql/data:/var/lib/mysql
- /home/dockerHome/mysql/conf/my.cnf:/etc/my.cnf
restart: always
web-api:
build:
context: .
image: i-fds-web-api
container_name: c-fds-web-api
ports:
- "8080:8080"
volumes:
- /home/logs:/logs
- /home/dockerHome/nginx/home/upload:/home/fds/fds-boot/upload
depends_on:
- mysql
- redis
- elaticsearch
- mongo
- rabbitmq
nginx:
image: nginx:1.19.2
container_name: c-fds-nginx
ports:
- "80:80"
- "443:443"
- "8880:8880"
volumes:
- /home/dockerHome/nginx/nginx.conf:/etc/nginx/nginx.conf
- /home/dockerHome/nginx/home:/home/
- /home/dockerHome/nginx/logs:/logs/
- /home/dockerHome/nginx/ssl:/ssl/
depends_on:
- web-api
elasticsearch:
image: elasticsearch:7.9.1
container_name: c-fds-elasticsearch
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /home/dockerHome/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /home/dockerHome/elasticsearch/config/jvm.options:/usr/share/elasticsearch/config/jvm.options
- /home/dockerHome/elasticsearch/config/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
- /home/dockerHome/elasticsearch/data:/usr/share/elasticsearch/data
- /home/dockerHome/elasticsearch/plugins:/usr/share/elasticsearch/plugins
environment:
ES_JAVA_POTS: "-Xms256m -Xmx256m"
discovery.type: "single-node"
mongo:
image: mongo:4.2.6
container_name: c-fds-mongo
restart: always
ports:
- "9000:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: "root"
MONGO_INITDB_ROOT_PASSWORD: "123456"
volumes:
- /home/dockerHome/mongo/config:/data/configdb
- /home/dockerHome/mongo/dbs:/data/dbs
- /home/dockerHome/mongo/db:/data/db
- ./mongodb:/docker-entrypoint-initdb.d/
rabbitmq:
image: rabbitmq:3.8.0-management
container_name: c-fds-rabbitmq
restart: always
ports:
- "9001:5672"
- "9002:15672"
environment:
RABBITMQ_DEFAULT_USER: "root"
RABBITMQ_DEFAULT_PASS: "123456"
volumes:
- /home/dockerHome/rabbitmq/data:/var/lib/rabbitmq
二、参数说明
version: “3” 代表docker-compose的书写语法
services: 里面定义服务
redis:
image: redis:5.0.9
container_name: c-fds-redis
ports:
- “6379:6379”
volumes:
- /home/dockerHome/redis/redis.conf:/etc/redis/redis.conf
- /home/dockerHome/redis/data:/data
这个定义了redis的环境,images是运行的镜像,container_name是运行容器的名称ports:代表着宿主机的6379端口映射到容器中的6379端口;volumes:代表宿主机的文件夹挂载到容器中的文件夹
mysql:配置文件类似redis
web-api:
build:
context: .
image: i-fds-web-api
container_name: c-fds-web-api
ports:
- “8080:8080”
volumes:
- /home/logs:/logs
- /home/dockerHome/nginx/home/upload:/home/fds/fds-boot/upload
depends_on:
- mysql
- redis
- elaticsearch
- mongo
- rabbitmq
web-api服务是对应的 java应用, depends_on:是依赖于mysql、redis、elasticsearch、mongo、rabbitmq服务,只有等他们都启动好了,才会启动这个服务