Aaron 2025-07-19 0

Taming Ephemeral Docker Logs with Delve

If you’ve ever worked with Docker, you’ve probably faced this scenario: a container misbehaves, you remove it to start fresh, and just like that, its logs are gone forever. The docker logs command is fantastic for real-time monitoring, but it only works for containers that exist. Once a container is removed, its history is wiped clean, leaving you with a frustrating gap when you need to perform a post-mortem.

This was the exact problem I wanted to solve. I needed a simple, persistent way to capture and browse the logs from all my containers without a complex setup. This need sparked a project that grew from a simple script into a full-fledged tool I’m now calling Delve (Docker Event & Log Viewer).

The Journey: From a Simple Script to a Full Application

The initial idea was straightforward: a Python script that could access the log files Docker creates on the host system, typically located in /var/log/docker/. I wanted a simple web interface to view them, so I started with a Python Flask backend to serve the files and a basic HTML frontend to display them.

This simple viewer quickly evolved as I considered how others might use it.

  1. Containerization: The most logical way to distribute a Docker tool is, of course, as a Docker container. This led to creating a Dockerfile to package the Python application.
  2. The Logging Daemon: Just viewing existing logs wasn’t enough. The real goal was to capture them. I created a daemon script that runs inside the Delve container, mounts the host’s Docker socket, and actively watches for other containers. When a new container starts, the daemon begins streaming its logs to a persistent file.
  3. Ease of Use: A tool is only useful if it’s easy to set up and manage. This led to the creation of two key scripts:
    • manage-logs.sh: A command-line tool to easily add or remove containers from a logging exclusion list.
    • setup-delve.sh: An interactive setup script that walks a new user through creating the docker-compose.yml file, configuring ports, and handling folder permissions.

This iterative process of identifying a need and building upon the solution is what shaped the final outcome.

The Outcome: Delve

The result of this journey is Delve, a tool I’m excited to share. It’s a self-contained, containerized application that provides a complete solution for persistent Docker log management.

Here are some of the key features:

  • Web-Based UI: View logs from any browser on your network.
  • Live Log Generation: A built-in daemon automatically discovers and captures logs from all other running containers.
  • Log Rotation: Automatically archives logs when a container restarts, preserving history.
  • Dynamic Search: A responsive search bar to quickly filter and find text within the current log file.
  • Exclusion Management: A command-line script to easily prevent specific containers from being logged.
  • Daemon Log Viewer: A dedicated button to view the internal log of the Delve application itself for easy debugging.

The Road Ahead

While Delve is fully functional today, there are several features I’m considering for the future to make it even more powerful and user-friendly:

  • UI-Based Settings: A settings page directly within the web interface to manage themes (like light and dark mode), the exclusion list, and other preferences without touching the command line.
  • Time and Date Filtering: The ability to filter logs based on specific date and time ranges, making it easier to zero in on events that occurred at a specific time.
  • Advanced Exclusion Options: When excluding a container, you’ll be able to choose whether to archive or delete its existing logs.
  • Time Zone Configuration: Support for setting a specific time zone for the container to ensure all timestamps are displayed correctly for your location.
  • Localization: Adding support for multiple languages in the user interface.
  • Multiple Server Logging: Add a back-end that can be run on other servers that will allow the UI to present logs from other services.

Get Started with Delve

I’ve published Delve on GitHub and Docker Hub, and you can get it running in just a few minutes using the setup script. Just use the code below to download and run the script. It will walk you through every step of the way.

wget https://github.com/aarondyck/delve/releases/download/v1.0.0/setup-delve.sh
chmod +x setup-delve.sh
./setup-delve.sh

The script will generate a docker compose file for you based on the information you provide. When the script reaches its end it will prompt you to start the container.

This project was a fantastic learning experience, and I hope you find it as useful as I do. Check out the repository on GitHub to see the code, and feel free to try it out!

Views: 22

Category: 

Leave a Comment