Lesson 1 · Unit 04
Configuration and secrets
One image for every environment, settings and secrets from outside
What you practise
- Settings from the environment, secrets kept out of images and layers, one image for every environment
Try a question from this lesson
Pick one
An image has the staging database address written into its code. It passed every test in staging. To run in production the address must change. What does that force?
Hint
Images are read-only. How do you change something that was built in?
Correct answer
A rebuild, so production runs an image nobody tested
Why
Built-in settings can only change by building again, and the rebuilt image is not the one that was tested. Keep what differs between environments out of the image, and the tested image can go everywhere.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Build once, configure at start
The image holds what is the same everywhere: the app and what it needs to run.
What differs between environments is passed in when the container starts, as environment variables: -e NAME=value, or --env-file for a file of them. The app reads them at startup.
docker run -d -e DB_HOST=db.staging \
shop/api:1.4.0
docker run -d -e DB_HOST=db.prod \
shop/api:1.4.0Concept
Secrets stay out of images
An image gets copied: to a registry, to every server, to every teammate. Whoever can pull it can read every file in every layer.
docker history also prints the instructions that built it, with the values of ENV and ARG.
So a password, token or key is never built in. It is handed to the container when it starts.
10 more exercises in the app
- 1× type the answer
- 5× multiple choice
- 1× true or false
- 1× fill the blanks
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.