Docker-compose file with multiple files/different variables

Hello ,

I’m currently working on integrating Doppler to manage secrets and environment variables for a Docker Compose setup that involves multiple services, each with their own specific configuration requirements. I aim to use Doppler to dynamically inject environment variables without needing to explicitly list every variable in the Docker Compose files. Here are some details about my setup:

  • Multiple Docker Compose Files: My application is structured with separate Docker Compose files for different components (e.g., docker-compose.db.yml for databases, docker-compose.api.yml for APIs). I’m considering how best to manage these with Doppler.
  • Service-Specific Variables: Each service has its own set of environment variables that are different from others, and I’d like to inject these dynamically from Doppler without explicitly listing them in the Compose files one by one, as that would be a long list.

I’ve looked into using the --mount-template option with the Doppler run command to inject environment variables dynamically, but I’m unsure how to effectively apply this when dealing with multiple Docker Compose files and ensuring that each service gets only the variables it needs.

Questions:

  1. What are the best practices for using Doppler with multiple Docker Compose files to manage service-specific environment variables dynamically?
  2. Is there an efficient way to ensure that each Docker Compose file/service can receive its specific environment variables from Doppler without explicitly listing each variable in the Docker Compose files?
  3. Can anyone share examples or insights on setting up such an environment, especially any pitfalls to avoid or tips for simplification?

Any advice or examples from your experiences would be greatly appreciated as I navigate setting up this system.

Thank you!!!

Hi @PapaPeskwo!

Welcome to the Doppler Community!

This is actually something we cover in our documentation. Take a look at option 1 here:

In particular, the “Multiple Services” section. Essentially, you pass in a separate Doppler access token for each service as the DOPPLER_TOKEN and then use doppler run:

DOPPLER_TOKEN_API="$(doppler configs tokens create --project api --config dev api-dev-token --plain --max-age 1m)" \
DOPPLER_TOKEN_WEB="$(doppler configs tokens create --project web --config dev web-dev-token --plain --max-age 1m)" \
docker-compose -f docker-compose.yml up

That example generates a new token at runtime, but you could also pass those in via some other method. Although this is specifically geared toward multiple services with one Docker Compose file, it should work fine if you have multiple files. Have you tried this already? If so, what problems did you run into?

Regards,
-Joel

1 Like