Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 444
Brandon Avatar asked Dec 04 '14 18:12

Brandon


1 Answers

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.

like image 101
Sentient07 Avatar answered Sep 29 '22 21:09

Sentient07