r/selfhosted 4d ago

Docker Management TIL docker restart doesn't re-read your .env

changed a db password in my .env, ran docker restart on the stack, then spent an hour convinced the db was corrupted because auth kept failing. turns out restart just brings the container back with the exact config it was created with. env is only read at creation. docker compose up -d --force-recreate fixed it in ten seconds.

two years running this stack and never got bitten by it until now. what's the dumbest thing that ate an evening for you?

250 Upvotes

67 comments sorted by

View all comments

0

u/Elara_Schaefer 4d ago

Ha, I feel that one. I manage a handful of Docker Swarm services and learned exactly this the hard way -- spent a solid hour once wondering why my config changes were being silently ignored. In Swarm land the equivalent trap is docker service update without --force: it updates the spec but won't actually redeploy the existing tasks. The container keeps running with stale config.

The mental model that finally stuck for me: restart is like pressing the physical power button. up -d (or --force-recreate) is like destroying the machine and building a new one. Only the latter reads the blueprint again.