Dynamically "define" what environment variables (and their values) to pass to Docker container using docker-compose

Viewed 16

I know that environment variables can be passed to a Docker container started with docker-compose up either on the command line (VAR1=VAL1 VAR2=VAL2 docker-compose up) or with an .env file. However, feeding the environment variables through on the command line requires them to be mapped in the docker-compose.yml file (under environment for the service to be started). For the example stated above, I would like to avoid having to specify VAR1 and VAR2 in the docker-compose.yml file. Is there any way to accomplish this?

EDIT: What I mean by having to specify VAR1 and VAR2 is the following (in the docker-compose.yml file):

services:
  dev:
    image: ...
    environment:
      VAR1=${VAR1}
      VAR2=${VAR2}
  ..
0 Answers
Related