I docker that output logs stdout stderr, which can be viewed using:

docker logs -f $LOGS_CONTAINER_ID

I also added 'sed', which puts the container id on each line:

docker logs -f $LOGS_CONTAINER_ID | sed "s/^/$LOGS_CONTAINER_ID /"

If I run it, I get something like:

container112 error 10:20:10 problem
container112 info 10:20:09 not problem
container112 error 10:20:01 problem

where "container112" is $LOGS_CONTAINER_ID.

SO FAR SO GOOD. Now I want to output the above command to a file (log.out), so I wrote the following command:

docker logs -f $LOGS_CONTAINER_ID | sed "s/^/$LOGS_CONTAINER_ID /" >> log.out

What happens is that it writes the logs to log.out, but it doesn't get new logs (if I open a new session and run tail -f log.out, I don't get output). So I also tried:

tail -f $(docker logs -f $LOGS_CONTAINER_ID | sed "s/^/$LOGS_CONTAINER_ID /") >> log.out

But it also didn't work. What is the problem?

  • Why would it have the new logs? Are you running something in the background? Your docker logs command only runs once. If you want more logs, you need to run it again. – terdon Mar 3 at 20:15
  • if I just run "docker logs -f $LOGS_CONTAINER_ID >> log.out", and on another session I run "tail -f log.out", I get new logs. – Yagel Mar 3 at 20:55
  • If you do docker inspect $CONTAINER_ID | grep log then you'll find a pathname where docker writes its logs to. You may be able to use that – Stephen Harris Mar 3 at 21:20
  • Possible duplicate of stackoverflow.com/q/577865/9447571, see if making sed unbuffered (either using -u or the stdbuf helper command) will fix your issue. – filbranden Mar 3 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.