Docker Compose
- 功能
使用 YML 文件来配置应用程序需要的所有服务。然后使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。
安装docker-compose 组件
- 查看版本
$ docker-compose version
yaml 文件
version: '3'
services:
backend:
image: "<image address>"
container_name: "<container name>"
hostname: "<hostname>"
network_mode: host
ports:
- <host port>:<container port>
restart: always
volumes:
- /etc/localtime:/etc/localtime
environment:
- <key>=<value>
command: "ls"
version: '2'
services:
mysql:
image: mysql:5.7
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=123456
volumes:
- "${PWD}/dockerData/mysql:/var/lib/mysql"
- "${PWD}/mysql.conf.d:/etc/mysql/mysql.conf.d/"
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--default-time-zone=+8:00']
redis:
image: "redis:alpine"
restart: always
command: redis-server --requirepass 123456
ports:
- "6379:6379"
rabbitmq:
image: rabbitmq:management-alpine
environment:
- RABBITMQ_DEFAULT_USER=${ENV_RABBITMQ_NAME}
- RABBITMQ_DEFAULT_PASS=${ENV_RABBITMQ_PASSWORD}
restart: always
ports:
- "15672:15672"
- "5672:5672"
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
用yaml文件构建镜像
$ cd yaml文件路径
$ docker-compose up