Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker not showing logs written in /dev/stdout

I started some docker containers with:

docker-compose up -d

(here the docker-compose.yml)

and then:

docker-compose logs -f web

but if I write on another shell:

docker-compose exec web echo "hello" >> /dev/stdout

Nothing appear in the live logs screen. Same for any other container. Why? Am I doing something wrong?

like image 708
Oscar Fanelli Avatar asked Oct 29 '25 03:10

Oscar Fanelli


2 Answers

/dev/stdout is different for each process. Your docker-compose logs will only show you the output of your PID 1 process, not other processes that run in that container namespace.

Update: also note:

  • >> /dev/stdout will be applying to docker compose exec web echo "hello" on the host .. not to echo "hello" inside the container
  • >> /dev/stdout is kind of a no-op because a process will write to stdout by default .. and, for stdout, >> (append) is the same as > (redirect) because there's no pre-existing output that can be overwritten/replaced.
like image 195
boyvinall Avatar answered Oct 31 '25 20:10

boyvinall


Solved putting this inside the virtualhost configuration:

CustomLog /proc/self/fd/1 combined
ErrorLog /proc/self/fd/2

So, in order to show up logs on docker, you can use /proc/self/fd/1 and /proc/self/fd/2

like image 38
Oscar Fanelli Avatar answered Oct 31 '25 22:10

Oscar Fanelli