我正在嘗試從 JSON 創建一個 docker compose 覆寫 YAML 檔案,其中包含N個 Traefik 標簽。我目前有以下設定:
{
"version": "3.7",
"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"
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"
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。
uj5u.com熱心網友回復:
yq e '... style="" | with(.traefik.labels[] ; . style="double")' docker-compose.override.json
產生所需的回應。
version: "3.7"
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"
解釋
... style=""為所有節點設定漂亮的列印樣式。with(.traefik.labels[] ; . style="double").traefik.labels僅使用雙引號設定樣式
或者只是yq e '... style="double"' docker-compose.override.json用來將鍵括在雙引號中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/394939.html
標籤:json docker-compose yq
