0

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
  • Do some of the logs go to stderr? Does adding 2>&1 to the end of that command help? Commented Sep 26, 2022 at 14:04
  • No it changed nothing. Commented Sep 26, 2022 at 14:06

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.