Pipe Log Output to STDOUT with Docker

InstructorMark Shust

Share this video with your friends

Send Tweet

Since Docker filesystems are ephemeral, it's important to take into account anything that writes or appends to disk, such as log files. It is standard practice when running Docker containers to pipe log file output to the console, to allow for simple diagnostic and to avoid append-only files from consuming disk space.

In this lesson, we’ll show you how to append output to STDOUT, and how to view log output from your running containers.

Wojciech Morkowski
~ 6 years ago

I dont't get this lesson. What's the purpose of creating debug.log file if we never write anything to it (at least in Docker environment)?

Mark Shustinstructor
~ 6 years ago

As noted in the video, this is a non-sensical example. But it demonstrates how you would change an app that normally writes to log files so that they instead pipe to STDOUT, so you can make the app 12-factor friendly.

You don’t need to create a log file if you are already piping things to STDOUT. Note that in this example, we are writing the console.log output directly to the debug.log file.

Wojciech Morkowski
~ 6 years ago

Ok thanks, I get it. You can also find great explanation here: https://stackoverflow.com/questions/43968560/how-to-log-the-12-factor-application-way/43968637#43968637

Dr.Emmett Brown
~ 6 years ago

it's good tip. Thank you.

Nehal Soni
~ 5 years ago

I can see the value in keeping the logging agnostic. How would you do this with statsd logging? This often requires a client side package with host name and port number. Would you pass those variables into the docker container? Or can you do a similar thing you do here with standard logging for stats?