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
raise Exception("!")
Then I run this file in docker container. But in /var/lib/docker/containers/.../...-json.log:
{"log":"Traceback (most recent call last):\n","stream":"stdout","time":"2015-06-17T23:10:01.58636849Z"}
{"log":" File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stdout","time":"2015-06-17T23:10:01.586581081Z"}
{"log":" raise Exception(\"!\")\n","stream":"stdout","time":"2015-06-17T23:10:01.586842665Z"}
{"log":"Exception: !\n","stream":"stdout","time":"2015-06-17T23:10:01.587373678Z"}
Apart from the previous answer (and my comment), there is the attach of
docker run
from the doc http://docs.docker.com/reference/commandline/cli/#run-a, --attach=[] Attach to STDIN, STDOUT or STDERR
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:
But if I run container in background, stream become stderr:
docker run -d my_python python /var/app.py
I think this behavior implicitly.
docker logs separating stdout from stderr:
vs