Docker-compose – 在添加日志选项后启动容器时遇到错误

huangapple go评论54阅读模式
英文:

Docker-compose - facing error while starting container after adding logging option

问题

我们的Docker版本是20.10.21,构建版本是baeda1f。在docker-compose.yml中没有指定日志选项时,它可以正常运行,但是当我们指定日志选项并启动docker-compose时,它会抛出错误“ERROR: for 无法为服务创建容器:json: 无法将数字反序列化为Go结构字段LogConfig.HostConfig.LogConfig.Config的字符串类型”。

这是docker-compose.yml中该服务的条目 -

    logging:
        driver: "json-file"
        options:
            max-file: 5
            max-size: 10m

请告诉我我们的配置可能有什么问题。感谢您的帮助。

英文:

We have Docker version 20.10.21, build baeda1f. It is running fine without logging options in docker-compose.yml but when we specify the logging options and then start docker-compose, it throws an error
"ERROR: for <servicename> Cannot create container for service <servicename>: json: cannot unmarshal number into Go struct field LogConfig.HostConfig.LogConfig.Config of type string"

This is the entry in docker-compose.yml under that service -

logging:
        driver: &quot;json-file&quot;
        options:
            max-file: 5
            max-size: 10m

Please let me know what might be wrong with our configuration. Appreciate your help.

答案1

得分: 5

原来我必须将 max-file 指定为字符串。四年前已经有人提出了这个问题,并自己找到了答案。
链接:https://stackoverflow.com/questions/54939953/docker-bjson-cannot-unmarshal-number-into-go-struct-field-logconfig-config-of

logging:
    driver: "json-file"
    options:
        max-file: "5"
        max-size: 10m

希望对某人有所帮助。

英文:

Turned out that I had to specify max-file as string. It was already asked by someone 4 years ago, who found the answer himself.
https://stackoverflow.com/questions/54939953/docker-bjson-cannot-unmarshal-number-into-go-struct-field-logconfig-config-of

logging:
        driver: &quot;json-file&quot;
        options:
            max-file: &quot;5&quot;
            max-size: 10m

Hope it helps someone.

huangapple
  • 本文由 发表于 2023年3月3日 21:35:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定