A multitiered configuration model lets one container image behave differently across environments. It combines settings built into the image, file-based overrides, and environment variables with a defined precedence, keeping deployment changes outside application code. section 18.5 section 18.4
Use the layers for different kinds of change:
- Keep release-level defaults in the container image. section 18.5
- Provide environment-level settings through an override file mounted by the container platform. section 18.5
- Use environment variables for feature-level adjustments, such as enabling metrics, changing a setting, or disabling a feature during an incident. section 18.4 section 18.5
The pattern also adapts legacy applications. A startup utility can translate environment variables and override files into the configuration files the application already expects, avoiding changes to its original code. Docker Compose can document these settings consistently while preserving application-specific details. section 18.4
Run one image with different settings
Run the image with defaults on port 8090, then mount a development override file and point the application to it on port 8091. Add an environment variable on port 8092 to change a feature-level setting, then query each /config endpoint to verify the result. section 18.4
# switch to the app directory: cd ch18/exercises/image-of-the-day # run a container with default configuration: docker container run -d -p 8090:80 diamol/ch18-image-of-the-day:2e # run with a config override file in a bind mount: docker container run -d -p 8091:80 ` -v "$(pwd)/config/dev:/config-override" ` -e CONFIG_SOURCE_PATH="/config-override/application.properties" ` diamol/ch18-image-of-the-day:2e # check the config settings: curl http:/./localhost:8090/config curl http:/./localhost:8091/config
Follow the runnable Docker commands to compare default configuration with a bind-mounted override and inspect both results. section 18.4
