A container image can pass testing and then run in development, test, and production without being rebuilt. Configuration supplies the settings that change between those environments: logging detail, database choice, connection details, or enabled features. The application must know where to load those settings and how to merge them. section 18.0 section 10.3
Start with defaults in the image, then provide environment-specific overrides. An application can read environment variables and files placed at known paths; a configuration library can combine them in a hierarchy. In the Node.js access-log example, node-config reads packaged defaults from `config`, files supplied at `config-override`, and environment-variable overrides. section 18.1
# switch to the exercise folder: cd ch18/exercises/access-log # run a container with the default config in the image: docker run -d -p 8080:80 diamol/ch18-access-log:2e # run a container loading a local config file override: docker run -d -p 8081:80 ` -v "$(pwd)/config/dev:/app/config-override" ` diamol/ch18-access-log:2e # check the config APIs in each container: curl http:/./localhost:8080/config curl http:/./localhost:8081/config
Run the same image with and without a mounted override directory, then compare the two `/config` responses. The override changes the environment name and disables metrics without changing the image. section 18.1
Docker Compose can supply settings through `environment`, `env_file`, and secrets. Use an environment variable for a setting such as the database provider; use a secret surfaced as a file for sensitive settings such as a connection string. Compose override files can select different values and services for each environment while retaining a common image. section 7.4 section 10.3
Listing 7.3 Compose services for an app with a Postgres database
services:
todo-db:
image: diamol/postgres:2e-12
ports:
- "5433:5432"
networks:
- app-net
todo-web:
image: diamol/ch06-todo-list:2e
ports:
- "8020:80"
environment:
- Database:Provider=Postgres
depends_on:
- todo-db
networks:
- app-net
secrets:
- source: postgres-connection
target: /app/config/secrets.json
This Compose example selects Postgres with `Database:Provider=Postgres` and places a connection secret at `/app/config/secrets.json`, where the application can read it. section 7.4
There is another option when a framework supports named environments: package each environment’s files in the image and select one at runtime. In the .NET example, `appsettings.json` supplies defaults, `appsettings.{Environment}.json` supplies named overrides, and environment variables can override file values. External files can still provide further overrides. section 18.2
Keep the distinctions clear: application configuration changes behavior inside a container; container configuration changes properties such as published ports and volume paths. Logging infrastructure has its own configuration too. For example, changing a Fluentd filter can alter which logs reach Elasticsearch without replacing application containers. section 10.5 section 19.4
Check an override before relying on it
Run the access-log containers and compare their `/config` responses. Then add `APP_METRICS_ENABLED=true` to the overridden container and check the response again. For a file-based logging change, inspect container logs; in Kubernetes, also test whether existing Pods load a newly injected file or need replacement. section 18.1 section 15.6






















