Skip to content

No logging strategy: logs lost on container restart

Quick summary

Your container logs are lost on restart — there is no log persistence or centralized logging.

Why this happens

  • Container logs are only written to stdout without a logging driver or log rotation

  • No centralized logging system is configured to collect and store container logs

  • Log files are written inside the container's ephemeral filesystem and lost on restart

Minimal example

✗ Broken code
# docker-compose.yml
services:
  app:
    image: myapp:latest
    # no logging config — logs lost on restart
✓ Fixed code
# docker-compose.yml
services:
  app:
    image: myapp:latest
    logging:
      driver: json-file
      options:
        max-size: '10m'
        max-file: '3'
    # or send to Loki/ELK for centralized logging

Configuring log rotation with json-file driver preserves logs across restarts and limits disk usage with max-size and max-file.

How to diagnose

  • Check if container logs are available after a restart with docker logs

  • Review the logging configuration in docker-compose or the container runtime

  • Verify that a centralized logging system is collecting logs from all containers

How to fix

  • Configure a logging driver like json-file with log rotation or send logs to a remote syslog

  • Set up a centralized logging system like ELK, Loki, or CloudWatch to collect container logs

  • Write logs to a persistent volume or external log service instead of the container filesystem

How to prevent

  • Always configure log rotation and a centralized logging system in production

  • Use structured logging and ship logs to a central store for search and retention

Related Resources

Related Glossary

Related Lessons

← Back to language