Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make docker-compose logs -f only show /dev/stderr

I've got a container which runs Apache2 and has some log files that print their input into /dev/stdout and /dev/stderr. When running docker-compose logs -f it blindly prints both stdout and stderr mixed. Is there any way to only show one of the two?

lrwxrwxrwx 1 root root 11 Oct 10 01:22 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Oct 10 01:22 error.log -> /dev/stderr
lrwxrwxrwx 1 root root 11 Oct 10 01:22 other_vhosts_access.log -> /dev/stdout

Ideally, I'd like to optionally switch between outputs. I could imagine --only-stderr and --only-stdout flags. I'm aware of possible workarounds for this, but I'm interested if this is natively possible.

like image 513
Ambidex Avatar asked Jan 09 '18 07:01

Ambidex


1 Answers

I see your point and I would need the same thing, but apparently it's not supported by docker-compose at the moment.

See this feature request: https://github.com/docker/compose/issues/6078


Although you cannot do that with docker-compose, you can still achieve something similar by following the logs of a particular Docker container.

You wrote "I'm aware of possible workarounds for this" so you might know it already, but it will hopefully help other people visiting this page :)

After executing docker-compose up, list your running containers:

docker ps

Copy the NAME of the given container and read its logs:

docker logs NAME_OF_THE_CONTAINER -f

To only read the error logs:

docker logs NAME_OF_THE_CONTAINER -f 1>/dev/null

To only read the access logs:

docker logs NAME_OF_THE_CONTAINER -f 2>/dev/null
like image 102
David Namenyi Avatar answered Nov 15 '22 17:11

David Namenyi