Skip to content

DevOps

docker restart does not re-read your env file

By ·

I added a new variable to the env file of a service running on two servers, then ran docker restart. The container showed as up, nothing errored, and one feature quietly never ran.

docker restart stops and starts the existing container with the environment it was created with. An env file is read when the container is created, by docker run or docker compose up, and not when it restarts.

docker exec myservice env | grep NEW_VAR   # what the container really has
docker rm -f myservice && docker run --env-file .env ...   # recreate it
# or, with compose:
docker compose up -d --force-recreate

When configuration does not seem to apply, I now check the container's live environment before I look at the file on disk.

All notes

Have something in mind?

Let’s build something useful.

Tell me about the idea, product, or workflow you’re working through.

Tap to say hello