vmorganp

Lazytainer: Sleep Docker Containers When They Are Idle

Lazytainer monitors network activity and stops or pauses labeled Docker containers when they are idle, then wakes them when traffic returns. It suits self-hosters who want selected services to use fewer resources when not in use.

Stars
773
Forks
29
Stars, last 7 days
+3

Our take

Health score

27/100

How it is scored
Activity
20
Community
45
Issues
21
Pull requests
21

+3 stars in the last 7 days

Overview

Lazytainer manages the idle state of selected Docker containers by monitoring network traffic. When a configured group has insufficient activity, it stops or pauses the containers; incoming traffic through Lazytainer can bring them back into service.

It is intended for self-hosted Docker setups where some services are used intermittently. Unlike an automatic host-wide service, it requires explicit container labels and routing the services' traffic through Lazytainer.

Key Features

  • Groups one or more labeled containers for coordinated sleep and wake behavior.
  • Monitors configured internal ports for network activity.
  • Supports stopping or pausing containers when they become idle.
  • Configures inactivity timeout, packet threshold, polling rate, and network interface per group.
  • Can base activity on packet counts while ignoring connected-client counts.
  • Provides optional verbose logging and IPv4/IPv6 toggles.

Use Cases

  • Self-hosters can reduce activity from media, web, or other services that are only used occasionally.
  • Home-lab operators can let selected Docker services sleep between visits while keeping them accessible through a configured entry point.
  • Operators with multiple related containers can put them to sleep and wake them together as a group.
  • Users who want to trade immediate availability for reduced idle resource use can choose a stop or pause sleep method.

Getting Started

Clone the repository and start its Compose stack:

git clone https://github.com/vmorganp/Lazytainer
cd Lazytainer
docker compose up

See the README for configuration details and examples.

Considerations

  • Only containers assigned a Lazytainer group label are managed, and their traffic must pass through Lazytainer.
  • The Lazytainer container needs access to /var/run/docker.sock, mounted read-only as specified by the project. Access to the Docker socket is a significant host-control capability, so consider the security implications in your deployment.
  • Group configuration requires internal service ports to be specified and forwarded through Lazytainer.
  • A service may be unavailable while stopped or paused and may take time to respond when traffic triggers it. Timeout, packet threshold, and polling settings affect this behavior.

Found this useful?

Share it with someone who would like Lazytainer.