gpt4 book ai didi

json - docker-compose json 日志记录驱动程序标签/环境

转载 作者:行者123 更新时间:2023-12-04 19:33:43 24 4
gpt4 key购买 nike

我一直在尝试以以下格式获取日志:

{"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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com