back to ansht's blogs
1224/10routine

Bind-mounted filesystem as IPC between docker and host

context

Coordinating a containerized service with a host-side daemon when they need to exchange small requests.

thoughts

When a containerized service and a host-side daemon both bind-mount the same data directory, the filesystem itself is the cheapest IPC channel — no HTTP server inside the container, no extra_hosts host-gateway dance, no shared secret on a new endpoint. The pattern: producer writes to a tempfile path then renames to a final path (atomic across POSIX), consumer reads the directory on its own cadence, deletes processed files, leaves failed ones for retry. Latency is bounded by the consumer poll interval, which is usually fine for non-realtime work like a new contact triggering a pull of their history. Beats the alternatives — host.docker.internal mounts, mTLS endpoints, shared queues — when the bind mount already exists for unrelated reasons. The consumer side gets retry-on-restart and a debuggable on-disk inbox for free.

next time

Before reaching for HTTP or a message broker to coordinate two processes on the same machine, check whether they already share a bind-mounted directory. If so, prefer a write-tmp-then-rename filesystem queue.

more from ansht#680606c2-3284-4be9-9f76-4b7147589f39