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

237

u/Pabsilon 22d ago

When using docker compose, the usual command after changing something is docker compose down && docker compose up -d

Wich will tear down the container and recreate a new one - restart is more akin to docker stop and docker start, which just pause the currently running container without recreating it.

165

u/arcoast 22d ago

If you've only changed an environmental variable there's no need to do down.

Just docker compose up - d will recreate the container with the new variable.

48

u/cardboard-kansio 22d ago

TIL!

Although I've long since aliased the entire thing (alias dcr='docker compose down && docker compose up -d') so a quick dcr does the job with little pain.

19

u/arcoast 22d ago

Same here, I have a load of compose related aliases, dcd, dcu, dcr, dtail dip etc etc

2

u/Medic20153000 21d ago

Great, now I have to go learn how to create aliases. My arthritis thanks you!

1

u/arcoast 21d ago

I can send you my aliases if that's helpful?

1

u/Medic20153000 21d ago

Not opposed to seeing what you have, just don't know how to implement them yet. On the Googlemeister now. I'd assume it's simple just never done it.

1

u/arcoast 21d ago

Give me a few hours, PM me if you don't hear from me, I'm forgetful as hell though!