Motivation: To run a basic health-check on a docker container by counting that a certain number of messages flow across stdout over a certain time horizon
Immediate goal: From within a shell started by docker exec
, read data that is being piped to stdout from the main process (PID 1)
I am not even sure if what I want is possible. If that is the case, an explanation as to why not would be much appreciated -- and would help advance my knowledge.
Steps to reproduce:
Start the container --
container1
docker run -it --name container1 ubuntu bash -c -i "COUNT=0; while true; do echo Keep the dance floor beat going; ((COUNT++)); sleep 1; echo \"Count is: \${COUNT}\"; done;"
In another terminal window,
docker exec
to start another process in the same containerdocker exec -it container1 bash
Can I somehow tail
/print
/read
the messages being passed over stdout by PID 1?
I understand that there are work arounds -- for example piping through tee
or otherwise writing to disk -- but was hoping for a magic bullet.
If you are OK with
strace
then try this:-p 1
is the PID-e write=1
is there to narrow the output to STDOUT (-e write=1,2
would show both STDOUT and STDERR)Depending on Docker version you might need to loosen up Docker's syscall security policy, e.g. by disabling it completely by adding
--security-opt seccomp:unconfined
todocker run
when starting the container:Read more about the Docker's seccomp profiles here (>1.10).
Tested with: