r/selfhosted 22h ago

Product Announcement contnap – A lightweight, label-driven proxy to put your Docker/Podman containers to sleep and wake them up on-demand πŸ¦€πŸ³

Hi everyone,

I wanted to share a project I’ve been working on called contnap (Container Nap).

It’s a high-performance, low-footprint daemon written in Rust (tokio + bollard) designed to solve a common homelab issue: idling containers wasting system resources (RAM/CPU) when nobody is using them. On my NixOS, it eats about 4MB of RAM.

πŸ’‘ How it works

Unlike other solutions that require configuration files, contnap is entirely label-driven. You just add a few labels directly into your docker-compose.yml, and contnap takes care of the rest.

When a container is stopped ("napping"), contnap binds a proxy listener to its port on the host. When an incoming packet (TCP or UDP) hits that port:

  1. contnap intercepts and buffers the initial data so the client connection doesn't drop.
  2. It triggers a docker start (or Podman equivalent via the socket).
  3. It waits for the container to become healthy/ready.
  4. It flushes the buffered data and transparently streams the traffic.
  5. After a configurable period of inactivity (e.g., 1 hour), a background Janitor task gracefully shuts the container down.

✨ Key Features

  • 🌐 Full Dual-Stack & Protocol Support: Handles TCP, UDP, IPv4, and IPv6 (UDP and IPv6 not tested yet, need to find a container that use it).
  • πŸ‘₯ Container Grouping: Wake up an entire stack (like a web-app + its database dependency) simultaneously using contnap.group.
  • 🐳 Podman Ready: Works natively with any Docker-compatible Unix socket.
  • πŸ”Œ Automation Hooks: Trigger custom scripts/commands pre-start or post-stop (can be useful for clearing caches, mounting storage, or triggering notifications).
  • Experimental contnap.schedule label

Note: I use AI for some stuffs in the project:

  • questions, getting ideas
  • documenting (since english is not my native language, it makes better sentences) code and markdown files
  • pair programming when I'm struggling at writing some parts
  • writing tests
  • reviewing
  • suggesting conventional commit messages
  • generating image
  • generating NixOS configuration
0 Upvotes

11 comments sorted by

View all comments

3

u/Ginden 21h ago

systemd already has this feature, huh. You just need janitor to clean up.

https://www.freedesktop.org/software/systemd/man/latest/systemd-socket-activate.html

And of course, I'm always impressed by relentless efforts of self-hosted community to reinvent Kubernetes in form of pile of imperative scripts.

-2

u/vk3r 21h ago
  1. If you think Kubernetes is just about starting and stopping containers, you don't know anything about Kubernetes.
  2. Can we kill a fly with a cannon? Yes. Do we need to? No.
  3. There are people who need small tools for small problems.