--- title: "Monitoring Outbound Container Traffic with Tetragon (Without Kubernetes)" date: 2026-11-16 tldr: "How I use Cilium Tetragon, a tiny Docker container-mapper, and Fluent Bit to monitor outbound TCP/UDP connections from my containers on a standalone Docker host—without Kubernetes." tags: - Docker - Security - Self-Hosting - Tech layout: post.njk lang: en translationKey: tetragon-docker-monitoring --- If you run a bunch of Docker containers on a VPS or homeserver, you probably know what's *listening* on your ports. But do you know what your containers are connecting *out* to? I wanted to get visibility into outbound network connections on my standalone Docker host using **Cilium Tetragon** (eBPF-based security observability). Most Tetragon tutorials assume you're running Kubernetes, where Tetragon automatically enriches events with pod and namespace names. On plain Docker, you only get raw container IDs. Here's how I solved that with a small three-container `docker-compose.yml` setup. ## The Architecture My stack in `/docker/tetragon` consists of three services: 1. **`tetragon`** (`quay.io/cilium/tetragon:v1.3.0`): Hooks `tcp_connect` and `udp_sendmsg` in the kernel via eBPF and writes `PROCESS_KPROBE` events to a rotating log file. 2. **`container-mapper`** (`docker:cli`): A tiny loop that writes `ID -> Name` mappings from `docker ps -a --no-trunc` into `containers.map` every 10 seconds. 3. **`fluent-bit`** (`fluent/fluent-bit:latest`): Tails `tetragon.log`, runs a Lua script (`enrich_container.lua`) to attach the human-readable container name from `containers.map`, and forwards the enriched JSON to my log collector. ## Filtering Out Noise with a TracingPolicy By default, tracing every `tcp_connect` and `udp_sendmsg` on a host produces a lot of noise (localhost, Docker bridge networks, WireGuard, etc.). In `tetragon.tp.d/external-network.yaml`, I use a `TracingPolicy` with `NotDAddr` selectors to ignore private, loopback, and link-local ranges—plus the server's own public IP: ```yaml apiVersion: cilium.io/v1alpha1 kind: TracingPolicy metadata: name: external-network-tracing spec: kprobes: - call: "tcp_connect" syscall: false args: - index: 0 type: "sock" selectors: - matchArgs: - index: 0 operator: "NotDAddr" values: - "0.0.0.0/8" - "127.0.0.0/8" - "10.0.0.0/8" - "172.16.0.0/12" - "192.168.0.0/16" - "169.254.0.0/16" - "::/128" - "::1/128" - "fc00::/7" - "fe80::/10" ``` And in the `tetragon` container command, I restrict the export to `PROCESS_KPROBE` events only (`--export-allowlist={"event_set":["PROCESS_KPROBE"]}`), with log rotation enabled (`50 MB`, 5 backups, compressed). ## The Docker Compose Setup ```yaml services: tetragon: image: quay.io/cilium/tetragon:v1.3.0 container_name: tetragon restart: unless-stopped privileged: true pid: host network_mode: host command: - --tracing-policy-dir=/etc/tetragon/tetragon.tp.d - --export-filename=/var/run/tetragon/tetragon.log - --export-file-max-size-mb=50 - --export-file-max-backups=5 - --export-file-compress=true - --export-allowlist={"event_set":["PROCESS_KPROBE"]} - --metrics-server= - --health-server-address=127.0.0.1:6789 volumes: - /sys/kernel/btf/vmlinux:/var/lib/tetragon/btf:ro - /docker/tetragon/tetragon.tp.d:/etc/tetragon/tetragon.tp.d:ro - /docker/tetragon/log:/var/run/tetragon container-mapper: image: docker:cli container_name: tetragon-container-mapper restart: unless-stopped entrypoint: ["/bin/sh", "-c"] command: - "while true; do docker ps -a --no-trunc --format '{{.ID}}\t{{.Names}}' > /out/containers.map.tmp && mv /out/containers.map.tmp /out/containers.map; sleep 10; done" volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - /docker/tetragon:/out fluent-bit: image: fluent/fluent-bit:latest container_name: tetragon-fluent-bit restart: unless-stopped network_mode: host depends_on: - tetragon - container-mapper volumes: - /docker/tetragon/log:/var/run/tetragon:ro - /docker/tetragon/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf:ro - /docker/tetragon/fluent-bit-db:/var/run/fluent-bit - /docker/tetragon/enrich_container.lua:/fluent-bit/etc/enrich_container.lua:ro - /docker/tetragon/containers.map:/fluent-bit/etc/containers.map:ro ``` ## What I Like (and What to Watch Out For) - **Zero app changes**: eBPF runs in the kernel, so none of my containers need sidecars or special flags. - **Readable logs**: The `container-mapper` + `enrich_container.lua` trick is dead simple and gives me actual container names instead of 64-character hex IDs. - **Privileged mode**: Tetragon needs `privileged: true`, `pid: host`, and `/sys/kernel/btf/vmlinux` mounted read-only. That's expected for eBPF tooling, but worth keeping in mind. Overall, it's been running quietly in the background and gives me a clean feed of every external connection leaving the server.