是否可以隐藏 docker 日志记录驱动程序选项或至少从文件中加载它们?
我想提交docker-compose.yml
VCS,但要LOKI_USER_ID
在LOKI_API_KEY
运行时挂载。
码头工人-compose.yml:
version: '3'
x-logging: &logging
logging:
driver: loki
options:
# \/\/\/
loki-url: "https://${LOKI_USER_ID}:${LOKI_API_KEY}@logs-prod-us-central.grafana.net/loki/api/v1/push"
# /\/\/\
services:
service1:
image: image1
restart: always
<<: *logging
service2:
image: image2
restart: always
depends_on:
- service1
<<: *logging
我试过像这样拆分它们:
日志记录.yml:
version: '3'
x-logging: &logging
logging:
driver: loki
options:
loki-url: "https://${LOKI_USER_ID}:${LOKI_API_KEY}@logs-prod-us-central.grafana.net/loki/api/v1/push"
码头工人-compose.yml:
version: '3'
services:
service1:
image: image1
restart: always
<<: *logging
service2:
image: image2
restart: always
depends_on:
- service1
<<: *logging
然后运行
docker-compose -f logging.yml -f docker-compose.yml config
但它无法解析*logging
别名:
ERROR: yaml.composer.ComposerError: found undefined alias 'logging'
in "./docker-compose.yml", line 12, column 9
这是非常值得期待的。
实现此目的的另一种方法是使用envsubst
和处理docker-compose.yml
文件:
loki.env.sh:
export LOKI_USER_ID="XXX"
export LOKI_API_KEY="YYY"
码头工人-compose.yml:
version: '3'
x-logging: &logging
logging:
driver: loki
options:
loki-url: "https://${LOKI_USER_ID}:${LOKI_API_KEY}@logs-prod-us-central.grafana.net/loki/api/v1/push"
# ...
并使用以下命令启动它:
source loki.env.sh
envsubst < docker-compose.yml | docker-compose up -d