DEV Community

Cover image for Why Docker Silently Turns Your Missing Config File Into an Empty Directory

Why Docker Silently Turns Your Missing Config File Into an Empty Directory

hoagminh on December 02, 2026

Almost everyone who runs Docker Compose has been burned by this exact sequence at least once: services: clickhouse: image: clickhouse/clic...
Collapse
 
userxnom profile image
Abdullah Naseer •

This is the exact failure that makes Docker's auto-directory behavior so nasty — not the crash loop itself, but the second failure it plants: the empty directory it leaves behind blocks the next deploy from writing the real clickhouse-init.sh, so one missed file becomes two failed deploys. The detail I would steal is the rmdir-only self-healing — most people reach for rm -rf there, and the [ -d ] && [ ! -L ] && realpath -m == path guard is the difference between cleaning up and wiping data someone put in that directory. One gap I kept looking for: the [ -f ] check catches a missing file, but what about a file that exists and is empty — a fetch that wrote 0 bytes? The mount succeeds, the container still crash-loops, and the error is a different cryptic one. Do you treat a 0-byte rendered file as missing too, or is that a separate check? And for the soft-check bucket, what decides looksLikeFile for an extensionless path that is not in your standard names list — say ./data/seed — does it warn, or stay silent?

Collapse
 
hoagminh profile image
hoagminh •

Thanks for the detailed feedback! We reproduced both cases on Linux with Docker 29, and you're right on both counts.

The 0-byte file was a real gap. Our hard check only used [ -f ], so an empty file passed validation and failed later inside the container. In 0.1.0, we verify the byte count on disk against the rendered content before renaming the temp file into place, so a short write can never replace the existing file. We also added [ -s ] to the pre-up check for rendered files that are expected to have content. Intentionally empty upstream files are still allowed.

The extensionless path was another gap. ./data/seed stayed silent because we only consulted the upstream listing when a bind source looked like a file. That meant a missing upstream file could be mistaken for a data directory.

We've changed that too: for templates with an upstream source, every bind source that the deploy doesn't write is now checked against the upstream listing. If a file exists upstream but wasn't fetched, rendering is refused before deployment. The lookup uses cached tree listings, not file contents.

Both fixes are in 0.1.0. Really appreciate you pointing these out!

Collapse
 
userxnom profile image
Abdullah Naseer •

Thanks for reproducing both and for the detail — the byte-count check against the rendered content is the sharper fix, since it catches a short write too, not just a 0-byte file. And checking every unwritten bind source against the upstream listing, instead of only the ones that look like files, closes the ./data/seed gap cleanly. One question on the intentionally empty upstream files you still allow: how does Nitrobase know one is intentional — is it the upstream listing itself, or an allowlist in the template?

Thread Thread
 
hoagminh profile image
hoagminh •

Neither: there's no allowlist and no separate flag. The decision comes from the rendered content itself, and for upstream files that content is pinned by Git.

When the deploy renders a file that's also a bind source, it records whether the rendered content is empty. A non-empty one gets the [ -s ] check on the server, and an empty one only gets [ -f ]. So "intentionally empty" means "the content we rendered and wrote was empty".

What makes that trustworthy for upstream files is how they're fetched. Each one is downloaded at a pinned commit and checked against the size and blob SHA in the Git tree listing before it's used. A file that's 0 bytes upstream has the well-known empty-blob SHA (e69de29…) and size 0 in the listing. A non-empty upstream file can't come back empty by accident, because a truncated or empty download fails the SHA check and the render stops. So an empty rendered file means the repository really has an empty file at that path at that commit. The write's byte-count check then makes sure what lands on the server matches.

For files the template renders itself, the empty value comes straight from the render. A template that renders a file empty, for example because a variable is empty, gets an empty file on purpose, and it's treated the same way.

The one gap this leaves: if an upstream project ships an empty placeholder that its own image actually needs to be non-empty, we'd mount it as-is. That's the upstream's contract, though, and the container would fail the same way under plain docker compose up

Thread Thread
 
userxnom profile image
Abdullah Naseer •

That is a really clean answer — no allowlist, no flag, just the rendered content plus a Git-pinned SHA check doing the distinguishing. The empty-blob SHA detail is the part I like most: a 0-byte upstream file is provably empty, so a truncated download cannot sneak through as "intentionally empty." And being honest about the remaining gap is good too — the upstream placeholder its own image actually needs non-empty is the upstream's contract at that point, not the check's fault. Have you ever actually hit that gap in practice, or has it stayed theoretical so far?

Collapse
 
smtahosin profile image
S M Tahosin •

The inode side of single file bind mounts is the cousin of this bug that got me. Many editors and tools like sed -i don't edit the file in place, they write a new file and rename it over the old one, so the path gets a new inode while the container keeps the old mounted one. You end up staring at a config on the host that the container will never see until it restarts. Mounting the parent directory instead of the single file avoids that, and it pairs well with your pre-up checks. Do you treat directory mounts as the default for config now, or only for files that change during deploys?

Collapse
 
hoagminh profile image
hoagminh •

You were absolutely right about the inode issue — we were doing exactly that. Rendered files were written to a temp file and renamed over the target, which gives them a new inode. And docker compose up -d doesn't recreate containers just because a bind-mounted file's content changed.

We've addressed this in 0.1.0:

  • Unchanged files are no longer rewritten, so their inode and mtime stay intact. We still correct their mode, including 0600 for secrets and the executable bit, without touching the mtime.
  • After up, we check whether a service's running container started before the mtime of any single file it bind-mounts. If it did, we recreate that service with --no-deps --force-recreate and restart its dependents. The comparison uses nanosecond precision where supported, and it also catches retries after a failed deploy.
  • Directory binds are left alone, since the application can see the updated file immediately and may reload it itself. We've also updated the template docs to recommend directory mounts for configs that support hot-reloading, as you suggested.

Thanks for catching this. It exposed a real deployment issue that the usual file-existence checks wouldn't have caught!

Collapse
 
smtahosin profile image
S M Tahosin •

That mtime check is a neat way to close the loop. Comparing container start against the file's mtime catches the failed-deploy retry case too, which a simple "did we write it this run" flag would miss. Preserving mtime while still fixing the mode is the right call as well, since chmod only touches ctime. Most tools get one of those two wrong. Shipping the fix in 0.1.0 already is fast work, appreciate you taking the report seriously.

Thread Thread
 
hoagminh profile image
hoagminh •

Thanks for taking the time to dig into the implementation and point out these edge cases. Feedback like this genuinely helps us make Nitrobase more reliable.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Glad it was useful. That empty-directory trap has bitten me before, so it was an easy one to spot. Good luck with Nitrobase.

Collapse
 
hritik_chaudhary_5db0056f profile image
Hritik Chaudhary •

The same thing happens without Compose. docker run -v ./file:/path creates a root-owned directory when the source is missing, while --mount type=bind,source=./file,target=/path refuses to start with "bind source path does not exist". In Compose the long syntax gives the same behaviour if you set bind: {create_host_path: false}, so the failure shows up at up time instead of as a crash loop inside the container. For files that must exist I would use that, plus a plain [ -f ] check in the deploy script before up. The check also covers the stale empty directory left by an earlier failed run, and rmdir only removes a directory that is empty, so it cannot take real data with it.

Collapse
 
hoagminh profile image
hoagminh •

Thanks for pointing out the distinction between -v and --mount, and the create_host_path: false option in Compose. That's a useful way to catch missing bind sources before they turn into container failures.

We've now added bind.create_host_path: false to rendered files that must exist. That means a missing file fails at docker compose up with "bind source path does not exist", rather than silently becoming a directory and causing a crash loop — even when someone runs Compose manually.

The exception is SELinux-labelled binds (:z / :Z), since the Mount API path doesn't support relabeling. Those still rely on the pre-up [ -f ] check and our rmdir-only cleanup.

Also, for custom Compose files where there's no upstream listing to consult, we now report the likely missing bind source when a service crash-loops and the directory created by the pre-up check is still empty.

These changes are in 0.1.0. Thanks again for the practical suggestions!