Complete the code to set an environment variable in a Docker Compose service.
services:
web:
image: nginx
environment:
- PORT=[1]The environment variable PORT is set to 80, which is the default HTTP port commonly used in web servers.
Complete the code to use an environment variable from the host system in Docker Compose.
services:
app:
image: myapp
environment:
- API_KEY=[1]In Docker Compose, to use a host environment variable, you wrap it in ${}. So ${API_KEY} injects the host's API_KEY value.
Fix the error in the environment variable syntax to correctly pass a variable with a default value.
services:
db:
image: postgres
environment:
- POSTGRES_PASSWORD=[1]The correct syntax to provide a default value for an environment variable in Docker Compose is ${VAR:-default}. This means use VAR if set, otherwise use default.
Fill both blanks to define environment variables using a .env file and override one variable inline.
services:
api:
image: myapi
env_file:
- [1]
environment:
- DEBUG=[2]The env_file key points to the .env file to load variables. The DEBUG variable is overridden inline to false.
Fill all three blanks to create a service with environment variables from a file, inline variables, and a default fallback.
services:
worker:
image: workerapp
env_file:
- [1]
environment:
- LOG_LEVEL=[2]
- RETRY_COUNT=[3]The env_file points to worker.env. The LOG_LEVEL and RETRY_COUNT variables use default values if not set in the environment.