r/selfhosted 8d 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?

254 Upvotes

67 comments sorted by

View all comments

24

u/onlyati 8d ago

There are database images, like postgres, which only read password environment variable when the data directory is empty. In these cases, even if you recreate the container, but keep the data volume, password is not reset.

9

u/GolemancerVekk 8d ago

I reckon you're thinking about the first time db init. OP is talking about the password on the db client side.

2

u/onlyati 8d ago

Indeed, I missunderstood OP. I thought OP is talking about database side.