How do you pass environment variables to Docker Compose containers when you are starting services?
Experience Level: Junior
Tags: Docker Compose
Answer
Run the following command:
docker compose --env-file=my-env-variables.txt up
If you don't provide the --env-file, file .env is used as a source from which the environment variables are loaded.
Related Docker Compose job interview questions
How do you display a Docker Compose commands that can be executed?
Docker Compose JuniorHow do you display a Docker Compose version that is currently installed?
Docker Compose JuniorHow do you create a Docker Compose file that is parametrized using environment variables?
Docker Compose JuniorHow do you create a custom network and configure a Docker Compose service to use this network?
Docker Compose JuniorHow do you pass an environment variable to a Docker Compose service container?
Docker Compose Junior