aiven
aiven

Reputation: 4313

docker-compose: how to keep showing logs in 'follow' mode even when container is down?

If you run docker-compose logs -f service in one terminal and try to restart service in other, then logging will be stopped and you will need to start dkc logs again. How to keep dkc logs running?

The only solution I've found so far is to run additional noop service which will not allow dkc logs to shut down. If this is the only solution then do you have any suggestion for simplest noop service which already exists on docker hub?

My workaround:

  1. add new noop service to the docker-compose.override.yml (I picked redis because it was already installed and is quite lightweight):
services: 
  noop: 
    image: redis:5-alpine
  1. run docker-compose logs -f service noop instead of with just service.
  2. run docker-compose stop/restart service. logs process will be kept alive by noop service.

Con:

Upvotes: 6

Views: 1632

Answers (1)

Maybe some information about what you are logging. For example on nginx or php containers we simply move logfiles outside of container just using volume to mount them to host machine, then you can parse them as you want.

    volumes:
      - /var/log/mysql/error_service_xy.log:/var/log/mysql/error.log

Upvotes: 1

Related Questions