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?
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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!
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?
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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
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?
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
Across the templates we ship, only Supabase has 0-byte files upstream, and neither one is a single-file bind:
volumes/snippets/.gitkeep keeps the snippets folder in Git. That folder is mounted as a directory (./volumes/snippets:/app/snippets), so the empty file is just content inside it, not a bind source.
volumes/db/init/data.sql is an empty seed file. In the release we pin, the compose file mounts the individual init scripts (roles.sql, jwt.sql, realtime.sql and so on), all non-empty, and doesn't mount data.sql at all.
None of the other templates (Appwrite, Plausible, n8n, PocketBase, Umami, RustFS) bind-mount an empty upstream file. So the empty-is-allowed path hasn't been exercised by a shipped template yet, and nobody has reported tripping over it.
Two caveats. First, 0.1.0 is our first stable release, so real-world mileage is still short. Second, the realistic way to hit the gap is a template bump: an upstream release that starts mounting a file it ships empty and expects you to fill. We'd catch that in review when updating the template's pinned version, and it would also fail under plain docker compose up.
Software engineer who builds things that run in production — and writes deep-dive guides on why they break. I explain how React, Node, Docker, Rust and Kubernetes actually work under the hood.
The inode side of single file bind mounts is the brother to this particular bug I encountered. Most editors and commands such as sed -i do not perform an in-place edit, rather, they create a new file and rename it over the old one. In effect, the path is assigned a different inode than the inode that the container retains from the mount. You find yourself looking at a config on the host that will never get seen by the container until the container is restarted. By mounting the entire parent directory instead of the single file, you can avoid this problem. And it goes hand-in-hand with your pre-up checks. Do you consider directory mounts the default for configs, or only those configs which change on deploys?
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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!
Software engineer who builds things that run in production — and writes deep-dive guides on why they break. I explain how React, Node, Docker, Rust and Kubernetes actually work under the hood.
The mtime check, that is a cool way to tie up loose ends. It will also pick up on the failed-deploy retry case that a simple "have we written this on this run" flag would miss. Keeping the mtime but correcting the mode, that is absolutely the correct thing to do, because chmod will only alter the ctime. Most utilities manage that poorly or not at all, in my experience. Appreciate you taking the report seriously, shipping the fix in 0.1.0 already is fast work.
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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.
Software engineer who builds things that run in production — and writes deep-dive guides on why they break. I explain how React, Node, Docker, Rust and Kubernetes actually work under the hood.
Great that it helped. The empty directory trick has caught me out before, so that one was easy for me to spot. Best of luck with your Nitrobase project.
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
If you find Nitrobase interesting, we'd really appreciate a star on GitHub! It would mean a lot to us and give us the motivation to keep improving the product and expanding its capabilities. Thanks so much for your support! ❤️
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.
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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!
rmdir, never rm -rf, is a small rule that says a lot. If the directory has anything in it, the deploy fails loudly instead of eating data.
I hit a cousin of the inode case smtahosin mentioned, on Docker Desktop for macOS. Single-file read-only bind mount, and a tool saved the host file as a new file. The container kept the old size, read the file cut short, JSON failed to parse, and my app store quietly showed an empty app list. touch didn't help, a container restart did.
Does your after-up check ever compare what the container sees, size or hash, with the host file?
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
No, it doesn't look inside the container. The checks are all on the host side, and the stale-inode case is handled by inferring staleness rather than measuring it.
What the deploy does today:
Doesn't rewrite unchanged files. If the file on the server already has the rendered content (compared by hash, plus mode), it stays put: same inode, same mtime. Most redeploys never create the problem in the first place.
Writes changed files atomically and checks them. A changed file goes to a temp file and is renamed into place. Before the rename, the deploy checks that the byte count matches what it rendered.
Decides staleness from timestamps. After writing, it compares each single-file bind source's host mtime with the StartedAt of the running containers that mount it. A container that started before the file last changed is treated as stale and recreated (--no-deps --force-recreate). compose up alone won't do that, because bind content isn't part of the config hash.
Recovers from earlier failures. The decision depends only on the server's current state, not on what this deploy wrote. So if a previous deploy wrote the files and then failed before up, the next one still notices the containers are stale.
Your Docker Desktop case would be caught on the next Nitrobase deploy: the tool's save bumped the mtime past StartedAt, so that service would be recreated. That's the same fix as the restart that worked for you, done automatically.
Where the gap is: nothing watches between deploys. If something outside Nitrobase replaces the file while the app is running, the container keeps the old view until the next deploy or a manual restart. We don't compare what the container sees with the host file.
We left out an in-container check deliberately. It needs stat or sha256sum in every image (many are distroless or scratch), and it means a docker exec per mount on every deploy. On top of that, the mtime-versus-start-time rule already covers the replace-the-inode case, which is the only way the two views drift apart. A truncated read like yours is the same inode problem showing up differently, not a separate failure mode.
I'm a Web Builder & Creative Web Developer who lives at the intersection of design, technology, and motion. I build digital experiences that feel polished, load fast, and leave a lasting impression.
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?
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/seedstayed 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!
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?
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
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?
Theoretical so far
Across the templates we ship, only Supabase has 0-byte files upstream, and neither one is a single-file bind:
volumes/snippets/.gitkeep keeps the snippets folder in Git. That folder is mounted as a directory (./volumes/snippets:/app/snippets), so the empty file is just content inside it, not a bind source.
volumes/db/init/data.sql is an empty seed file. In the release we pin, the compose file mounts the individual init scripts (roles.sql, jwt.sql, realtime.sql and so on), all non-empty, and doesn't mount data.sql at all.
None of the other templates (Appwrite, Plausible, n8n, PocketBase, Umami, RustFS) bind-mount an empty upstream file. So the empty-is-allowed path hasn't been exercised by a shipped template yet, and nobody has reported tripping over it.
Two caveats. First, 0.1.0 is our first stable release, so real-world mileage is still short. Second, the realistic way to hit the gap is a template bump: an upstream release that starts mounting a file it ships empty and expects you to fill. We'd catch that in review when updating the template's pinned version, and it would also fail under plain docker compose up.
The inode side of single file bind mounts is the brother to this particular bug I encountered. Most editors and commands such as sed -i do not perform an in-place edit, rather, they create a new file and rename it over the old one. In effect, the path is assigned a different inode than the inode that the container retains from the mount. You find yourself looking at a config on the host that will never get seen by the container until the container is restarted. By mounting the entire parent directory instead of the single file, you can avoid this problem. And it goes hand-in-hand with your pre-up checks. Do you consider directory mounts the default for configs, or only those configs which change on deploys?
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 -ddoesn't recreate containers just because a bind-mounted file's content changed.We've addressed this in 0.1.0:
0600for secrets and the executable bit, without touching the mtime.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-recreateand restart its dependents. The comparison uses nanosecond precision where supported, and it also catches retries after a failed deploy.Thanks for catching this. It exposed a real deployment issue that the usual file-existence checks wouldn't have caught!
The mtime check, that is a cool way to tie up loose ends. It will also pick up on the failed-deploy retry case that a simple "have we written this on this run" flag would miss. Keeping the mtime but correcting the mode, that is absolutely the correct thing to do, because chmod will only alter the ctime. Most utilities manage that poorly or not at all, in my experience. Appreciate you taking the report seriously, shipping the fix in 0.1.0 already is fast work.
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.
Great that it helped. The empty directory trick has caught me out before, so that one was easy for me to spot. Best of luck with your Nitrobase project.
If you find Nitrobase interesting, we'd really appreciate a star on GitHub! It would mean a lot to us and give us the motivation to keep improving the product and expanding its capabilities. Thanks so much for your support! ❤️
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.
Thanks for pointing out the distinction between
-vand--mount, and thecreate_host_path: falseoption 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: falseto rendered files that must exist. That means a missing file fails atdocker compose upwith "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 ourrmdir-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!
rmdir, neverrm -rf, is a small rule that says a lot. If the directory has anything in it, the deploy fails loudly instead of eating data.I hit a cousin of the inode case smtahosin mentioned, on Docker Desktop for macOS. Single-file read-only bind mount, and a tool saved the host file as a new file. The container kept the old size, read the file cut short, JSON failed to parse, and my app store quietly showed an empty app list.
touchdidn't help, a container restart did.Does your after-
upcheck ever compare what the container sees, size or hash, with the host file?No, it doesn't look inside the container. The checks are all on the host side, and the stale-inode case is handled by inferring staleness rather than measuring it.
What the deploy does today:
Doesn't rewrite unchanged files. If the file on the server already has the rendered content (compared by hash, plus mode), it stays put: same inode, same mtime. Most redeploys never create the problem in the first place.
Writes changed files atomically and checks them. A changed file goes to a temp file and is renamed into place. Before the rename, the deploy checks that the byte count matches what it rendered.
Decides staleness from timestamps. After writing, it compares each single-file bind source's host mtime with the StartedAt of the running containers that mount it. A container that started before the file last changed is treated as stale and recreated (--no-deps --force-recreate). compose up alone won't do that, because bind content isn't part of the config hash.
Recovers from earlier failures. The decision depends only on the server's current state, not on what this deploy wrote. So if a previous deploy wrote the files and then failed before up, the next one still notices the containers are stale.
Your Docker Desktop case would be caught on the next Nitrobase deploy: the tool's save bumped the mtime past StartedAt, so that service would be recreated. That's the same fix as the restart that worked for you, done automatically.
Where the gap is: nothing watches between deploys. If something outside Nitrobase replaces the file while the app is running, the container keeps the old view until the next deploy or a manual restart. We don't compare what the container sees with the host file.
We left out an in-container check deliberately. It needs stat or sha256sum in every image (many are distroless or scratch), and it means a docker exec per mount on every deploy. On top of that, the mtime-versus-start-time rule already covers the replace-the-inode case, which is the only way the two views drift apart. A truncated read like yours is the same inode problem showing up differently, not a separate failure mode.
Your exit 97 check for clickhouse-init.sh made me recheck my own bind mounts before my next compose up.
Haha, mission accomplished! 😄 If this saves you from one mysterious
Is a directoryerror, my work here is done. Thanks for giving the article a read!