Dash in Docker: Stdout prints not being flushed to host terminal

I’m running a python dash app inside a docker container. However flushing print statements to the host terminal do not work. I’ve tried:

  1. print("test", flush=True)

  2. Setting PYTHONUNBUFFERED=1 or =0 in dockerfile or in docker run

  3. Running python with the -u (unbuffered) flag

docker-compose not printing stdout in Python app - Stack Overflow seems to be a similar if not the same problem.

anyone with the same issue?

It had to do with the fact that I am using an anaconda environment inside the docker container and miniconda as base image. Adding to the ENTRYPOINT conda python in my dockerfile the --no-capture-output flag solved the problem.

Hello @luggie,

You can also set this up with supervisor, which I prefer from gunicorn. :grin:

I did not mention gunicorn so far. I must say, I do not get what you are trying to say :smiley: Please explain :slight_smile:

Hello @luggie,

In my setups, I run a linux supervisor, that controls gunicorn, which is configured to take the print outs to a file. This is especially helpful for when you are running the application in a permanent install.

ah right, now I got you. In my setup I run a systemd service that starts a docker container on server boot. Inside the container is my miniconda and dash is started by gunicorn as well.
I’ll have a look at your setup. Thanks for the inspiration!

1 Like