How do I display output from Python application running inside Docker container?

Brandon picture Brandon · Dec 4, 2014 · Viewed 9.1k times · Source

So, I've got some Python code running inside a Docker container. I started up my local env using Google's gcloud script. I'm seeing basic access style logs and health check info, but I'm not sure how I can pass through log messages I'm writing from my Python app to the console. Is there a parameter I can set to accomplish this with my gcloud script or is there something I can set in the Dockerfile that can help?

Answer

Sentient07 picture Sentient07 · Jun 12, 2015

For Python to log on your terminal/command line/console, when executed from a docker container, you should have this variable set in your docker-compose.yml

  environment:
    - PYTHONUNBUFFERED=0

This is also a valid solution if you're using print to debug.