docker-compose里两种设置volumes方式

绝对路径的

1
2
3
4
5
ghost: 
image: ghost
volumes:
- ./ghost/config.js:/var/lib/ghost/config.js

卷标的

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
version: "3.2"
services:
ch:
build:
context: .
dockerfile: clickhouse.Dockerfile
cache_from:
- yandex/clickhouse-server:latest
ports:
- "8123:8123"
volumes:
- ch_db:/var/lib/clickhouse
networks:
- clickhouse
# restart: always
tabix:
image: spoonest/clickhouse-tabix-web-client
ports:
- "8124:80"
networks:
- clickhouse
depends_on:
- ch
networks:
clickhouse:
volumes:
ch_db:

第一种情况路径直接挂载到本地,比较直观,但需要管理本地的路径,而第二种使用卷标的方式,比较简洁,但你不知道数据存在本地什么位置,下面说明如何查看docker的卷标

  • 查看所有卷标
1
docker volume ls 
  • 查看批量的卷标
1
2
3
$ docker volume ls | grep mysql

local vagrant_mysql
  • 查看具体的volume对应的真实地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
docker volume inspect clickhouse_ch_db
[
{
"CreatedAt": "2021-11-18T03:29:17Z",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "clickhouse",
"com.docker.compose.version": "2.1.1",
"com.docker.compose.volume": "ch_db"
},
"Mountpoint": "/var/lib/docker/volumes/clickhouse_ch_db/_data",
"Name": "clickhouse_ch_db",
"Options": null,
"Scope": "local"
}
]