Python exceptions in Docker logs marked as stream: stdout

前端 未结 3 1529
猫巷女王i
猫巷女王i 2021-01-26 18:17

I want parse and handle all errors from docker container, but python exceptions marked as stdout, when I expect stderr.

As example simple app.py

3条回答
  •  感情败类
    2021-01-26 18:24

    I had a misconception. I thought that the command of docker CLI does not affect the main logs (/var/lib/docker/containers/.../...-json.log)

    But in case with:

    docker run -it my_python python /var/app.py

    json.log content:

    {"log":"Traceback (most recent call last):\n","stream":"stdout","time":"2015-06-18T10:02:55.842010241Z"}
    {"log":"  File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stdout","time":"2015-06-18T10:02:55.842252975Z"}
    {"log":"    raise Exception(\"error\")\n","stream":"stdout","time":"2015-06-18T10:02:55.842423153Z"}
    {"log":"Exception: error\n","stream":"stdout","time":"2015-06-18T10:02:55.842754372Z"}
    

    But if I run container in background, stream become stderr:

    docker run -d my_python python /var/app.py

    {"log":"Traceback (most recent call last):\n","stream":"stderr","time":"2015-06-18T10:02:18.905673576Z"}
    {"log":"  File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stderr","time":"2015-06-18T10:02:18.90575399Z"}
    {"log":"    raise Exception(\"error\")\n","stream":"stderr","time":"2015-06-18T10:02:18.905802834Z"}
    {"log":"Exception: error\n","stream":"stderr","time":"2015-06-18T10:02:18.90616668Z"}
    

    I think this behavior implicitly.

提交回复
热议问题