【发布时间】:2021-12-26 20:46:44
【问题描述】:
我正在尝试从 JSON 创建一个 docker compose 覆盖 YAML 文件,其中包括 N 个 Traefik 标签。我目前有以下设置:
{
"version": "3.7",
"services": {
"traefik": {
"labels": [
"traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local",
"traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local",
"traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local",
"traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
]
}
}
}
目前使用以下命令:
yq e -P docker-compose.override.json
结果:
version: "3.7"
services:
traefik:
labels:
- traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local
- traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local
- traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local
- traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local
- traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local
- traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local
但我想在 traefik 标签周围加上双引号,如下所示:
version: "3.7"
services:
traefik:
labels:
- "traefik.http.routers.traefik-secure.tls.domains[0].main=domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.domain1.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].main=domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[1].sans=*.domain2.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].main=domainN.local"
- "traefik.http.routers.traefik-secure.tls.domains[N].sans=*.domainN.local"
我将如何实现这一目标?我可以编辑 JSON,但我希望更好地使用 yq。
【问题讨论】:
-
首先,yaml 是 json 的超集,因此您可以继续使用 docker compose 运行您的 json 文件。其次,yaml 中的引号是可选的。只有当您想要一个数字或一些特殊值作为字符串时,您才需要引用它们。因此,不引用它们不会对您造成伤害。
标签: json docker-compose yq