我一直在尝试以以下格式获取日志:
{"log":"Using CATALINA_BASE: /opt/apache-tomcat-
7.0.76\r\n","stream":"stdout","time":"2017-04-
19T04:28:33.608418994Z","attrs":
{"production_status":"testing","os":"ubuntu"}}
我正在使用 docker-compose.yml :
version: '2.1'
services:
web:
image: hello-world/web:latest
container_name: api
ports:
- "80:8080"
logging:
driver: "json-file"
options:
max-size: 10m
max-file: "3"
labels: testing
env: ubuntu
但是我没有在日志中得到“attrs”键。我究竟做错了什么?
最佳答案
根据我的测试,有 2 个部分可以让标签/环境变量显示在日志中。
所以,为了得到你想要的,你需要将 docker-compose.yml 设置为:
version: '2.1'
services:
web:
image: hello-world/web:latest
container_name: api
ports:
- "80:8080"
logging:
driver: "json-file"
options:
max-size: 10m
max-file: "3"
labels: "production_status"
env: "os"
labels:
production_status: "testing"
environment:
- os=ubuntu
关于json - docker-compose json 日志记录驱动程序标签/环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43486505/