2

I am trying to get the real time stdout from a command I am running in a docker container. However, I need to do this from a remote command run from another host.

When I am on the docker host I can run my docker command with -it and get the real time output I need. However, I have this constraint where I have to run the command remotely making the previous solution useless. I cannot use -t because it runs a pseudo terminal based on $TERM which doesn't exist with the remote command because there is no terminal at all.

I have also tried running the docker command with -d to run it in the background and docker logs -f <container> but the output is still given all at once at the end of the process.

Any solutions or advice is appreciated and correct me if this belongs on another stack.

1

Well why don't you use ELK stack with logsprout you can get real time logs from all docker containers plus you can search among the logs and lot of other cool stuffs

  • Logspout looks like it could be helpful, I will look more into that – Pythonic Apr 18 '17 at 14:24
  • If you will face any problem let me know – varnit Apr 18 '17 at 14:24
  • Is your problem solved? – varnit Apr 18 '17 at 17:50
  • No my problem is that for some reason my code is real time in the stdout of a terminal, but not in the stdout of a container. – Pythonic Apr 19 '17 at 13:05
1

Figured this out from some help on Docker's github. I failed to mention I was trying to run a python script in the container, but I didn't think it was important.

This was actually not a docker problem, but a python issue. I learned Docker already does provide stdout in realtime. Python was holding all the stdout in its buffer and not flushing until the completion of the script. Except when the code was run in a terminal with -t.

In the docker command all I needed was to call the script with python -u <script> to prevent python from buffering the stdout.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.