Docker run, docker exec and logs
If I do this:
docker run --name nginx -d nginx:alpine /bin/sh -c 'echo "Hello stdout" > /dev/stdout'
I see "Hello stdout" when I do this:
docker logs nginx
But when the container is running (docker run --name nginx -d nginx: alpine) and I do:
docker exec nginx /bin/sh -c 'echo "Hello stdout" > /dev/stdout'
or when I attach the container with:
docker exec -it nginx /bin/sh
and then:
echo "Hello stdout" > /dev/stdout
I don't see anything in the docker logs. And since my Nginx access logs are redirected to / dev / stdout, I can't see them either.
What's going on with this standard?
source to share
When you docker exec
see you have multiple processes
/ # ps -ef
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
6 nginx 0:00 nginx: worker process
7 root 0:00 /bin/sh
17 root 0:00 ps -ef
/ #
and on Linux each process has its own stdin, stdout, stderr (and other file descriptors), in / proc / pid / fd
and so, with your docker exec
(pid 7) you will output something in
/ Proc / 7 / FD / 1
while your nginx process (pid 1) displays its output in
/ Proc / 1 / FD / 1
source to share