stdout being buffered in docker container

后端 未结 2 1943
刺人心
刺人心 2021-02-09 11:45

I\'m not entirely sure what is going on here but it appears that stdout is being buffered when I run my code in a container, but not if I run it on the host or on OSX.

h

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 12:07

    Is this what you're asking?

    Why am I seeing my output in chunks? Is it being buffered and flushed somewhere?

    Yes. Your Docker container is running on a Docker engine (possibly wrapped by a Docker machine) and your commands are being run from a client. Even if your engine is installed locally and you're running your container in interactive mode, the commands you're entering and the output you're seeing are still basically the results of HTTP requests against localhost. (Or Unix Socket or TTY communications.) (I'm simplifying.) Docker is routing I/O through your network drivers, i.e. its stdout has to be flushed to a (virtual?) network connection, and then the client flushes that to your stdout.

    In background mode, the engine captures stdout and (by default) writes to a file. The docker logs command sends a request from your client to the engine, and the engine responds by reading back the contents of that file.

提交回复
热议问题