compose容器编排是什么?
compose下载安装
官网:https://docs.docker.com/compose/compose-file/compose-file-v3/
官网下载:https://docs.docker.com/compose/install/
下载比较快的网站:https://get.daocloud.io/#install-compose
# 下载docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.16.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 设置权限
chmod +x /usr/local/bin/docker-compose
compose核心概念
compose使用的三个步骤
compose常用命令
# 更新某个服务
docker-compose up --detach --build zhiyu-nginx
# 查看容器日志后100行
docker logs -f -t --tail=100 c337e9df72a7
compose.yaml文件
version : '3.8'
services:
# 服务名字
zhiyu-nacos:
# 容器名字
container_name: zhiyu-nacos
# 镜像
image: nacos/nacos-server
#启动服务时,先将build中指定的Dockerfile打包成镜像,再运行该镜像
build:
context: ./nacos
# 配置docker容器的环境变量
environment:
- MODE=standalone
# 对应的容器卷
volumes:
- ./nacos/logs/:/home/nacos/logs
- ./nacos/conf/application.properties:/home/nacos/conf/application.properties
# 端口映射
ports:
- "8848:8848"
- "9848:9848"
- "9849:9849"
# 定义容器启动顺序 (此选项解决了容器之间的依赖关系, 此选项在 v3 版本中 使用 swarm 部署时将忽略该选项)
depends_on:
# - 服务名
- zhiyu-mysql
zhiyu-mysql:
container_name: zhiyu-mysql
image: mysql:5.7
build:
context: ./mysql
ports:
- "3306:3306"
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/logs
- ./mysql/data:/var/lib/mysql
# 覆盖容器启动后默认执行的命令, 支持 shell 格式和 [] 格式
command: [
'mysqld',
'--innodb-buffer-pool-size=80M',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-zone=+8:00',
'--lower-case-table-names=1'
]
environment:
MYSQL_DATABASE: 'zy-cloud'
MYSQL_ROOT_PASSWORD: password
zhiyu-redis:
container_name: zhiyu-redis
image: redis
build:
context: ./redis
ports:
- "6379:6379"
volumes:
- ./redis/conf/redis.conf:/home/zhiyu/redis/redis.conf
- ./redis/data:/data
command: redis-server /home/zhiyu/redis/redis.conf
zhiyu-nginx:
container_name: zhiyu-nginx
image: nginx
build:
context: ./nginx
ports:
- "80:80"
volumes:
- ./nginx/html/dist:/home/zhiyu/projects/zhiyu-ui
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/logs:/var/log/nginx
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- zhiyu-gateway
links:
- zhiyu-gateway
zhiyu-gateway:
container_name: zhiyu-gateway
build:
context: ./zhiyu/gateway
dockerfile: dockerfile
ports:
- "8080:8080"
depends_on:
- zhiyu-redis
links:
- zhiyu-redis
zhiyu-auth:
container_name: zhiyu-auth
build:
context: ./zhiyu/auth
dockerfile: dockerfile
ports:
- "9200:9200"
depends_on:
- zhiyu-redis
links:
- zhiyu-redis
zhiyu-modules-system:
container_name: zhiyu-modules-system
build:
context: ./zhiyu/modules/system
dockerfile: dockerfile
ports:
- "9201:9201"
depends_on:
- zhiyu-redis
- zhiyu-mysql
links:
- zhiyu-redis
- zhiyu-mysql
zhiyu-modules-gen:
container_name: zhiyu-modules-gen
build:
context: ./zhiyu/modules/gen
dockerfile: dockerfile
ports:
- "9202:9202"
depends_on:
- zhiyu-mysql
links:
- zhiyu-mysql
zhiyu-modules-job:
container_name: zhiyu-modules-job
build:
context: ./zhiyu/modules/job
dockerfile: dockerfile
ports:
- "9203:9203"
depends_on:
- zhiyu-mysql
links:
- zhiyu-mysql
zhiyu-modules-file:
container_name: zhiyu-modules-file
build:
context: ./zhiyu/modules/file
dockerfile: dockerfile
ports:
- "9300:9300"
volumes:
- ./zhiyu/uploadPath:/home/zhiyu/uploadPath
zhiyu-visual-monitor:
container_name: zhiyu-visual-monitor
build:
context: ./zhiyu/visual/monitor
dockerfile: dockerfile
ports:
- "9100:9100"