使用Docker Compose管理多个容器 Docker Compose是一个用来定义和运行复杂应用的Docker工具。使用Compose,你可以在一个文件中定义一个多容器应用,然后使用一条命令来启动你的应用,完成一切准备工作。 一个使用Docker容器的应用,通常由多个容器组成。使用Docker Compose,不再需要使用shell脚本来启动容器...
使用Docker Compose管理多个容器
Docker Compose是一个用来定义和运行复杂应用的Docker工具。使用Compose,你可以在一个文件中定义一个多容器应用,然后使用一条命令来启动你的应用,完成一切准备工作。
一个使用Docker容器的应用,通常由多个容器组成。使用Docker Compose,不再需要使用shell脚本来启动容器。在配置文件中,所有的容器通过services来定义,然后使用docker-compose脚本来启动,停止和重启应用,和应用中的服务以及所有依赖服务的容器。完整的命令列表如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| build 构建或重建服务
help 命令帮助
kill 杀掉容器
logs 显示容器的输出内容
port 打印绑定的开放端口
ps 显示容器
pull 拉取服务镜像
restart 重启服务
rm 删除停止的容器
run 运行一个一次性命令
scale 设置服务的容器数目
start 开启服务
stop 停止服务
up 创建并启动容器
|
rmw-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| version: "2"
services:
saasPages:
image: rmw-pages:v1.0
container_name: saasPages
environment:
TZ: Asia/Shanghai
restart: always
ports:
- "8077:80"
- "8088:8088"
- "4090:4090"
volumes:
- ./hosts:/etc/hosts
- ./saasPages/dist:/usr/share/nginx/html/
- ./saasPages/manage:/opt/manage
- ./saasPages/nginx.conf:/etc/nginx/nginx.conf
- /file_share:/file_share
- /file_share/https:/file_share/https
saasManage:
image: rmw-manage:v1.0
container_name: saasManage
environment:
TZ: Asia/Shanghai
restart: always
ports:
- "8075:80"
volumes:
- ./hosts:/etc/hosts
- ./saasManage/manage:/usr/share/nginx/manage/
- ./saasManage/nginx.conf:/etc/nginx/nginx.conf
- /file_share:/file_share
saasWeb:
image: rmw:ffmepg1.4
container_name: saasWeb
environment:
TZ: Asia/Shanghai
LANG: C.UTF-8
restart: always
ports:
- "8076:8076"
volumes:
- ./skywalking-agent:/opt/skywalking-agent
- /etc/localtime:/etc/localtime
- ./java:/opt/java
- ./saasWeb:/opt/project
- ./hosts:/etc/hosts
- /file_share:/file_share
|