-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompose.yaml
103 lines (95 loc) · 4.5 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
services:
gin_demo1:
# build: ./gin_demo_docker_compose ###标识 Dockerfile 的路径名。根据指定路径里的Dockerfile,来构建image.
build:
context: ./gin_demo_docker_compose ##指定了dockerfile文件 的路径,可以是链接到 git 仓库的 url. 也可是相对路径,绝对路径。
dockerfile: Dockerfile ##指定 自定义构建的dockerfile, 使用此文件来构建。
args:
- GIT_COMMIT=cdc3b19 ## 指定参数,该参数在构建时传给 Dockerfile中的 ARG GIT_COMMIT
healthcheck: ### 检查容器是否在运行。
disable: true
image: gin_demo:v1 ##指定已存在镜像名和版本, 如果该项和 build 项同时指定,那么优先使用该项,而不是build项。
container_name: gin_demo1
user: root
volumes:
- type: bind
source: /home/user/works/docker_compose/demo/gin_demo_docker_compose/logs
target: /home/user/demo/logs
- type: bind ####指定了bind,那么 source的值: ../test_dir 必须要在本地Host 上存在,可以不是 顶层volumes定义的
source: ../test_dir ### 不是 顶层volumes定义的
target: /home/user/demo/test_demo_c
- type: volume ####指定了 volume,source 值可以是顶层 volumes定义的值,如果其他服务的容器也挂载了,这样可以保证和其他容器中共享。
source: test_dir
target: /home/user/demo/test_demo_c2
depends_on:
- gin_demo2
ports:
- "8080:8080" ### 端口映射, HOST:CONTAINER 的方式指定端口,可以是: "9090-9091:8080-8081"
environment:
req_ip: "172.18.0.1"
restart: on-failure
networks: ##指定服务容器加入的网络。
- gin_net
# network_mode: bridge ### 设置服务容器的网络模型 不能和 networks同时设置。 有这些值: none, host, bridge.
sysctls: ### 设置容器的内核参数等。
net.core.somaxconn: 1024
ulimits: ### 设置容器的默认限制值。
nofile:
soft: 20000
hard: 40000
privileged: true
# commond: "" #指定新的运行命令替代 Dockerfile中 CMD
# command:
# - 提供参数: provide default arguments for the ENTRYPOINT instruction,
# - both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.
# working_dir: /home/user/demo ##重写 image中的 WORKDIR
gin_demo2:
build: ./gin_demo2
image: gin_demo2:v1
container_name: gin_demo2
ports:
- "8081:8081"
volumes:
# - /home/user/works/docker_compose/demo/gin_demo2/logs:/home/user/demo2/logs:rw ###其中rw 是容器对path的读写权限。
- ./gin_demo2/logs:/home/user/demo2/logs:rw
- test_dir:/home/user/demo2/test_demo_c:rw ######### test_dir 可以是 顶层 volumes 定义的,如果其他服务的容器也挂载了,这样可以保持和其他container进行数据共享。
environment:
req_ip: "172.18.0.1"
depends_on:
- redis_demo
networks:
- gin_net
redis_demo:
image: redis:6.2.5
container_name: redis_demo
command: redis-server
ports:
- 6379:6379
volumes:
- ./data/redis/data:/data:rw ###容器可以读写这个目录, 有rw, ro
- test_dir:/data/test_demo_c_vv:rw ####### test_dir 可以是 顶层 volumes定义的,如果其他容器也挂载了这个卷名,那么可以和其他容器共享该目录中的数据。
networks:
- gin_net
sysctls: ### 设置容器的内核参数等。
net.core.somaxconn: 1024
# vm.overcommit_memory: 1
nginx:
image: nginx
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 15s
timeout: 30s
retries: 5
start_period: 30s
self_define_service:
image: ubuntu:20.04
container_name: self_def_service_c
restart: always ### 通过 docker compose ps 查看到 一直在重启。
command: ["echo", "this is demo"] ###覆盖image中声明的CMD; 如果 该值为: [] ,那么image中的命令不会被执行,如果没有设置该值,那么就使用Image 中的CMD值。
networks:
gin_net:
driver: bridge #####这些值: none, host, bridge.
other_net: #### 设置另外一种网络,可以在其他的service中的 networks 字段设置。
volumes:
test_dir: ### test_dir 是一个卷名,用于在多个 container之间保持数据同步,但是和本地的host 没有任何关联。 在本地host 该目录不一定要存在。
test_dir_2: