liveBook · Manning

Multitiered configuration model

As explained in Learn Docker in a Month of Lunches, Second Edition

A multitiered configuration model combines default settings, file-based overrides, and environment variables with defined precedence between them.

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

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains configuration layers, legacy loading, Compose documentation, and verification commands, but does not detail a universal precedence algorithm.
Examples
Demonstrates Docker runs, bind-mounted properties files, metrics flags, legacy loaders, Compose services, and configuration API checks.
What it assumes
Assumes basic Docker usage and configuration concepts while demonstrating the pattern through concrete commands rather than abstract theory.
What you can do after
Operate/configure one image across environments, override settings without rebuilding, and verify effective values through configuration endpoints.
How it connects
Connects container images with CI/CD pipelines, configuration files, environment variables, Docker Compose, secrets, and Kubernetes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.