1

In my docker container I have some logging files.

docker-compose-dev.yml
                     entrypoint.sh
                     web/
                        celery_logs/
                                   log1.log
                                   log2.log
                                   logn.log

These logs add up while tasks are running.

Is there a way or command to clean up the contents of all log files each time I run the container like so?

docker-compose -f docker-compose-dev.yml up -d 

entrypoint.sh

#!/bin/sh

echo "Waiting for postgres..."

while ! nc -z web-db 5432; do
  sleep 0.1
done

echo "PostgreSQL started"

python manage.py run -h 0.0.0.0
8-Bit Borges
  • 9,643
  • 29
  • 101
  • 198

3 Answers3

0

Docker file (Opcional)

First, if you just need to see less output, you can have docker only show you the more recent lines:

docker logs --since 30s -f <container_name_or_id>

Or you can put a number of lines to limit:

docker logs --tail 20 -f <container_name_or_id>

From : StackOverFlow#41091634

Manual

In this case it's the better solution, manually :

 rm -rf celery_logs/*
Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
0

You can force recreation of the containers:

docker-compose -f docker-compose-dev.yml up -d --force-recreate

Also you can write the logs to the console, and then docker will be able to handle the logging using it's own drivers, which can configure max-size of log files, etc...

matanper
  • 881
  • 8
  • 24
0

You can try to do a rm -rf inside the entrypoint script -

#!/bin/sh

rm -rf celery_logs/*
echo "Waiting for postgres..."

This way all the log files will be cleared whenever you launch a new container. You can give an absolute path if required.

vivekyad4v
  • 13,321
  • 4
  • 55
  • 63