# Docker Madness - When The Output Order of Debugging Seems Impossible

DevFeed: [Docker Madness - When The Output Order of Debugging Seems Impossible](<https://devfeed.tech/articles/docker-madness-when-the-output-order-of-debugging-seems-impossible-28160.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/docker/2020/07/31/docker-madness-when-the-output-order-of-debugging-seems-impossible.html>)

Author: Fuzzygroup

Published: 2020-07-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Docker](<https://devfeed.tech/topics/docker.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Python](<https://devfeed.tech/topics/python.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [Tensorflow](<https://devfeed.tech/topics/tensorflow.md>), [GPU](<https://devfeed.tech/topics/gpu.md>)

Tags: [aws](<https://devfeed.tech/tags/aws.md>), [code](<https://devfeed.tech/tags/code.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [docker](<https://devfeed.tech/tags/docker.md>), [gpu](<https://devfeed.tech/tags/gpu.md>), [python](<https://devfeed.tech/tags/python.md>), [tensorflow](<https://devfeed.tech/tags/tensorflow.md>)

## AI overview

This article explains that Docker can buffer application output, making debugging logs appear out of order. It recommends running Python in unbuffered mode with Docker by changing the command to `python3 -u ./main.py`.

## Source excerpt

Yesterday I was stuck in a hellish debugging cesspool - you know what I mean - when you are debugging a mysterious crash right down embedding line by line print statements and nothing is making sense. And I don't mean that its not making a lot of sense; I mean that its making NO DAMN SENSE. I was debugging on a GPU instance on AWS that was running a TensorFlow application and what I kept seeing was output appearing before the routine invoking it was executing. And this was a worst case scenario right down to the very first line of my Python code being: print("AT START") Happily I was pairing with my colleague Grant and he did that wonderful pairing step of "this makes no damn sense; let me apply my Google Fu to this" and he discovered that Docker buffers output at times and he recommend this change to the Dockerfile: Before: # rest of Dockerfile appears here CMD [ "python3", "./main.py" ] After: # rest of Dockerfile appears here CMD [ "python3", "-u", "./main.py" ] Here is the relevant Stack Overflow post. Thank you Grant!