0
0
Dockerdevops~5 mins

Environment files (.env) in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an environment file (.env) in Docker?
An environment file (.env) is a simple text file that stores key-value pairs used to set environment variables for Docker containers. It helps keep configuration separate from code.
Click to reveal answer
beginner
How do you use a .env file with a Docker Compose file?
You place the .env file in the same directory as the docker-compose.yml file. Docker Compose automatically loads variables from the .env file and replaces them in the compose file where referenced.
Click to reveal answer
beginner
What is the syntax for defining variables inside a .env file?
Each line contains a key and value separated by an equals sign, like VAR_NAME=value. No spaces around the equals sign are allowed.
Click to reveal answer
beginner
How can you reference environment variables from a .env file inside a docker-compose.yml?
Use the syntax ${VAR_NAME} inside the docker-compose.yml file to substitute the value from the .env file.
Click to reveal answer
beginner
Why is it useful to use .env files in Docker projects?
They help keep sensitive data like passwords out of code, make configuration easy to change without editing files, and support different setups for development, testing, and production.
Click to reveal answer
Where should you place the .env file for Docker Compose to automatically load it?
AIn the user's home directory
BInside the Docker image
CIn the root of the operating system
DIn the same directory as docker-compose.yml
What is the correct format for a variable in a .env file?
AVAR_NAME=value
BVAR_NAME: value
CVAR_NAME = value
DVAR_NAME => value
How do you use a variable from a .env file inside docker-compose.yml?
A{{VAR_NAME}}
B$VAR_NAME
C${VAR_NAME}
D%VAR_NAME%
Which of these is NOT a benefit of using .env files?
AMaking configuration easy to change
BAutomatically building Docker images
CKeeping sensitive data out of code
DSupporting different environments like dev and prod
If a variable is missing in the .env file, what happens when Docker Compose tries to use it?
AIt leaves the variable empty or uses a default if provided
BDocker Compose crashes immediately
CIt replaces the variable with 'null'
DIt prompts the user to enter a value
Explain how to create and use a .env file with Docker Compose.
Think about where the file goes and how variables are written and used.
You got /4 concepts.
    Describe the benefits of using environment files (.env) in Docker projects.
    Consider security and flexibility advantages.
    You got /4 concepts.