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.

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself