skip to Main Content

I run a simple Flask application in a docker container.

To run it i do :

docker run --name my_container_name my_image_name

The logs are redirected to stdout. So after this command, i see as an output :

 * Serving Flask app 'main'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://172.17.0.2:8080
Press CTRL+C to quit

When i want to get the logs with a separate command, i do :

docker container logs my_container_name

It returns well the logs. Exactly the same output as the output written above.

But if I try to redirect the output to a file :

docker container logs my_container_name > mylogfile.log

I don’t get all the logs! I get only :

 * Serving Flask app 'main'
 * Debug mode: off

Why that ?

2

Answers


  1. Chosen as BEST ANSWER

    Running the container with a dedicated Pseudo-TTY solves the problem.

    docker run -t --name my_container_name my_image_name
    

    The parameter "-t" solved my issue.....But i don't understand why.


  2. No need to redirect logs, just use:

    tail -f `docker inspect --format='{{.LogPath}}' my_container_name`
    

    or if you don`t like it , you can try:

    docker logs -f my_container_name &> my_container.log
    

    the trick is the &> which redirects both pipes to the file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search