4. Making Configuration Data Available to Containerised Applications Flashcards
What is application configuration?
An app’s configuration is everything that is likely to vary between deploys (staging, production, dev environments, etc).
What are some examples of application configuration?
- Database server URL for an app’s backend.
- Port the app listens on for client requests.
- An application’s logging level for debugging purposes.
- The version of the app or API served by the environment.
What are the Twelve Factor App recommendations around configuration?
- Separate code and config — don’t define configuration as constants in the application’s source code.
- Store config in env vars — do use environment variables to define the application’s configuration.
What are the benefits of using environment variables rather than the app’s source code to define configuration?
- No leakage of sensitive information hard-coded in software applications.
- Straightforward onboarding of new environments to host software applications.
- No need to re-test software applications due to changes to the configuration.
- Configuration defined in environment variables is agnostic concerning languages and operating systems.
What Dockerfile instruction do we use to define environment variables?
The ENV
instruction.
What can be said about the availability and persistence of environment variables defined in the Dockerfile for building images vs running containers?
Environment variables we define in the Dockerfile are available for builds. They can be used by other Dockerfile instructions.
These variables persist in the container. They are present in containers derived from the image build using the Dockerfile.
What is the recommended method of defining environment variables in the Dockerfile?
Using the ENV
instruction followed by the variable name, an equal sign, and variable value. Then, if you need more than one variable, you can use the backslash to define each one in a new line.
ENV REDIS_HOST="redis_server" \ REDIS_PORT="6379"
What kind of flexibility does Docker provide in regards to the point and time that environment variables are define?.
Environment variables can either be defined inside the Dockerfile or at the point of build. The latter meaning that the environment variables can be assigned when image builds are initiated.
How can we define an environment variable at the point of build?
- Arguments are provided on the command line when an image build is initiated with a Dockerfile.
- A corresponding variable is defined in the image’s Dockerfile using the ARG instruction.
- The value provided for the variable on the command line is substituted into the Dockerfile.
How do we define in the Dockerfile a command line argument to be passed when initiating a build?
By using the ARG
instruction followed by the argument name, an equals sign and the default value.
ARG VERSION="1.18.0"
How do we specify the value of an argument defined in the Dockerfile when running an image build?
By using the --build-arg
option followed by the argument name, an equals sign and the argument value.
docker build --build-arg VERSION="1.19.5"
What benefit does the fact that Docker ARG
instruction allows us to re-assign values to variables in command-line allow us to do?
It allows us to build different image variants without altering the Dockerfile by choosing the value of the variable at the point in time of the build.
What facts about the ARG
instruction should you take into consideration when deciding whether to use it to define a variable?
- It’s for values only known at build-time.
- Useful for variables required only for builds.
- Scoped from the line in which it is defined.
- Not visible when inspecting an image.
In what process/location can we access a variable defined using the ARG
instruction?
Only during the build process. Variables defined using the ARG
instruction don’t trickle down to containers that are derived from the image.
What facts about the ENV
instruction should you take into consideration when deciding whether to use it to define a variable?
- General-purpose mechanism for defining variables.
- Useful for persisting variables in images.
- ENV variables trump same-named ARG variables.
- Visible in image’s configuration.