Docker-compose命令-config

命令

docker-compose config

描述

Validate and view the Compose file
验证并查看Compose文件

用法

1
config [options]

选项

1
2
3
4
5
6
7
8
9
Options:
--resolve-image-digests Pin image tags to digests.
--no-interpolate Don't interpolate environment variables.
-q, --quiet Only validate the configuration, don't print anything.
--services Print the service names, one per line.
--volumes Print the volume names, one per line.
--hash="*" Print the service config hash, one per line.
Set "service1,service2" for a list of specified services
or use the wildcard symbol to display all services.

注意

示例

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
# 报错提示
$ docker-compose config
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 2, column 3
$ docker-compose config
ERROR: Named volume "demo-logs:/logs:rw" is used in service "demo" but no declaration was found in the volumes section.

# 显示服务名称
$ docker-compose config --services
demo
# 显示存储卷名称
$ docker-compose config --volumes
demo-logs
# 显示当前compose配置文件中所有服务的md5值
$ docker-compose config --hash="*"
demo d84b3c9a8aa196e1538fb9c9ccc09644dca20c91f76c88399e75f08d42db7b5f
# 目录结构
$ tree
├── data
│ └── demo.txt
├── docker-compose.yml
└── Dockerfile
$ cat Dockerfile
FROM alpine:3.13
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
CMD ["/bin/bash"]
# compose配置文件内容
$ cat docker-compose.yml
version: "3.8"
services:
demo:
build: .
image: demo:1.1.0
restart: always
volumes:
- ./data:/data
- demo-logs:/logs
volumes:
demo-logs:
# 查看并格式化显示compose配置文件
$ docker-compose config
services:
demo:
build:
context: /root/demo
image: demo:1.1.0
restart: always
volumes:
- /root/demo/data:/data:rw
- demo-logs:/logs:rw
version: '3.8'
volumes:
demo-logs: {}