简体   繁体   中英

Docker container logging

There is something I don't understand with Docker logs.

Reading the documentation I see that, by default, Docker uses the JSON File logging driver.

By default, Docker captures the standard output (and standard error) of all your containers, and writes them in files using the JSON format

So, if I'm doing

docker run -it --name log1 alpine:latest

followed by (so inside the container) a simple ps -ef , I can see the result of the command in the logs using docker logs log1

Now I'm keeping the container running. If, in another session, I'm doing

docker exec -it log1 ps -ef

nothing more arrives in the logs.

Even with

docker exec -it log1 sh

ps -ef (inside the container) produces nothing in the logs.

Back to the 1st session, all commands output is logged again.

What am I misunderstanding ?

I was unable to find explicit explanation for that on docker's site, but to me it looks like following.

First, when you start your container ( docker run ), dockder allocates main process ( PID 1 ) for that and container is considered alive while this process doesn't exit. This process has its own stdin , stdout and stderr , which are btw connected to your console ( -it flag).

These are the handlers, which are being collected and logged by docker daemon.

When you run docker exec , it creates new process in the container, and this new process does not inherit io handlers ( stdin , stdout and stderr ) from PID 1 . So, all new sessions, created by docker exec seem to have their own, separate streams, not being logged by daemon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM