Skip to content

Add automatic reconnection when containers restart#1

Open
eviltik wants to merge 1 commit intojoemiller:masterfrom
eviltik:feature/auto-reconnect-on-container-restart
Open

Add automatic reconnection when containers restart#1
eviltik wants to merge 1 commit intojoemiller:masterfrom
eviltik:feature/auto-reconnect-on-container-restart

Conversation

@eviltik
Copy link

@eviltik eviltik commented Oct 23, 2025

Summary

This PR adds automatic reconnection capability to docker-tail when monitored containers are restarted. Previously, if a container was restarted while being monitored, docker-tail would stop showing logs for that container, requiring a manual restart of the tool.

Changes

  • Wrapped docker logs -f command in an infinite monitoring loop for each container
  • Added container status check before attempting to connect (docker ps --format '{{.Names}}')
  • Implemented 2-second retry delay between reconnection attempts
  • Preserved color coding and prefix formatting across reconnections

Behavior

Before: When a container restarts, its log output stops permanently until docker-tail is manually restarted.

After: When a container restarts, docker-tail automatically detects it and reconnects within ~2 seconds, seamlessly resuming log output.

Testing

To test this feature:

  1. Start docker-tail with one or more containers
  2. Restart one of the monitored containers (docker restart <container>)
  3. Observe that log output automatically resumes after ~2 seconds

Technical Details

Each container is now monitored in a subprocess with a loop that:

  • Checks if the container is running before each connection attempt
  • Connects with docker logs -f if the container is available
  • Waits 2 seconds before retrying if the connection drops
  • Maintains the same color and prefix formatting across reconnections

The signal handling (SIGINT/SIGTERM) remains unchanged and properly terminates all monitoring subprocesses when docker-tail is stopped.

Compatibility

This change is backward compatible and does not affect the command-line interface or existing functionality. It only adds resilience to container restarts.

🤖 Generated with Claude Code

Wrap docker logs -f in a monitoring loop that automatically reconnects
when a container restarts. This prevents losing tail output when containers
are stopped and restarted during monitoring.

Changes:
- Add infinite loop around docker logs command for each container
- Check if container is running before attempting to connect
- Wait 2 seconds between reconnection attempts
- Maintain color and prefix formatting across reconnections

Fixes issue where docker-tail would stop showing logs after a container
restart, requiring manual restart of the docker-tail command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@eviltik
Copy link
Author

eviltik commented Oct 23, 2025

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant