Desk Clarity

A field guide to everyday digital problems.

Developer tools / Practical guide

Compose Restart Keeps Old Environment Values: Review and Recreate the Service

Restarting an existing container does not apply a changed Compose environment configuration.

By ON Lab2 min readSources checked November 10, 2026 (KST)

Restarting an existing container does not apply a changed Compose environment configuration. Inspect the resolved model, then use the reviewed service recreation path when the configuration really changed.

Inspect the relevant boundary

These commands illustrate a reviewed diagnostic workflow. They were not run against a live Docker service. Replace placeholder service and path names only after inspecting your own project.

# Illustrative commands only; replace SERVICE with your service.
docker compose config --services
# Review resolved configuration locally; it may contain secrets.
docker compose config
docker compose ps SERVICE
# After reviewing impact and persistence, apply the changed model:
docker compose up -d SERVICE
# Inspect only the intended nonsecret variable:
docker compose exec SERVICE printenv APP_MODE

Why the result changes

Separate three questions: what value the Compose model contains, what environment the container received when created, and what the application actually reads. A correct .env edit does not prove that a running container was recreated. A new container environment also does not rewrite an application setting already persisted in a database. Identify the same Compose project and service throughout the comparison.

Choose and verify the correction

First confirm that the resolved model contains the intended nonsecret value. If it does not, inspect interpolation inputs and precedence before changing the running service. If it does, plan for the service interruption and verify persistent storage, then apply up to the named service. Compose recreates containers when their configuration or image changed. Force recreation only when that behavior is intentionally needed; it is not a substitute for finding the effective configuration. Recheck the selected value and application behavior afterward.

Limits and next checks

These commands were checked against official documentation, not executed against a live service. Do not publish full config or environment output containing credentials. Image build arguments, runtime environment and database initialization variables are different contracts. Rebuilding an image is not a universal way to update runtime settings, and deleting volumes is not a configuration refresh step.

Related: Compose Expands the Wrong Variable: Separate Configuration and Container Expansion.

Official Docker documentation reviewed November 10, 2026 (KST); no live image build, service restart or container recreation was performed.

Sources & further reading