This example demonstrates using an immutable configuration container with plain Docker means. It uses Docker volumes under the hood to link the configuration container with the application container.
-
Create the application Docker Image first, which uses demo.war :
docker build -t k8spatterns/demo:1 -f Dockerfile-demo .
-
Now create config-dev container, which holds the configuration for the developer environment. The first step here is to create an image (with version number) and then a container from it
docker build --build-arg config=dev.properties -f Dockerfile-config -t k8spatterns/config-dev:1 .
docker create --name config-dev k8spatterns/config-dev:1 .
-
Start demo image with config-dev
docker run --volumes-from=config-dev -p 8080:8080 k8spatterns/demo:1
-
The application is now reachable as http://localhost:8080/demo. Use the address for your Docker daemon here (in most cases, it is "localhost").
The exact process can be done now for the production environment, but using now prod.properties
to create a configuration container for the production environment:
docker build --build-arg config=prod.properties -f Dockerfile-config -t k8spatterns/config-prod:1 .
docker create --name config-prod k8spatterns/config-prod:1 .
docker run --volumes-from=config-prod -p 8080:8080 k8spatterns/demo:1