0
0
Dockerdevops~10 mins

Environment variables in Compose in Docker - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set an environment variable in a Docker Compose service.

Docker
services:
  web:
    image: nginx
    environment:
      - PORT=[1]
Drag options to blanks, or click blank then click option'
A5000
B8080
C3000
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using a port number that is not standard for HTTP.
Leaving the environment variable value empty.
2fill in blank
medium

Complete the code to use an environment variable from the host system in Docker Compose.

Docker
services:
  app:
    image: myapp
    environment:
      - API_KEY=[1]
Drag options to blanks, or click blank then click option'
A${API_KEY}
BAPI_KEY
C$API_KEY
D$$API_KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using just $API_KEY without braces.
Using the variable name as a plain string.
3fill in blank
hard

Fix the error in the environment variable syntax to correctly pass a variable with a default value.

Docker
services:
  db:
    image: postgres
    environment:
      - POSTGRES_PASSWORD=[1]
Drag options to blanks, or click blank then click option'
A${POSTGRES_PASSWORD-defaultpass}
B$POSTGRES_PASSWORD-defaultpass
C${POSTGRES_PASSWORD:-defaultpass}
D$POSTGRES_PASSWORD:-defaultpass
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the colon before the dash.
Using $ without braces for default values.
4fill in blank
hard

Fill both blanks to define environment variables using a .env file and override one variable inline.

Docker
services:
  api:
    image: myapi
    env_file:
      - [1]
    environment:
      - DEBUG=[2]
Drag options to blanks, or click blank then click option'
A.env
Bproduction.env
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong filename for the env_file.
Setting DEBUG to a string that is not recognized as boolean.
5fill in blank
hard

Fill all three blanks to create a service with environment variables from a file, inline variables, and a default fallback.

Docker
services:
  worker:
    image: workerapp
    env_file:
      - [1]
    environment:
      - LOG_LEVEL=[2]
      - RETRY_COUNT=[3]
Drag options to blanks, or click blank then click option'
Aworker.env
B${LOG_LEVEL:-info}
C${RETRY_COUNT:-3}
Ddefault.env
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect env file names.
Not using default value syntax for environment variables.