Home > front end >  Inputting multiple command line arguments with docker-compose up
Inputting multiple command line arguments with docker-compose up

Time:06-01

I've noticed that docker-compose run has command-line input argument functionality with the -e flag, where running

docker-compose run -e ARG1="val1" -e ARG2="val2"

is valid. I'm however using docker-compose up, where the flag is not included. I've found a way to include a single variable:

ARG1="val1" docker-compose up

but how do I add multiple? I've tried separating by comma, semicolon, and others, but there seems to be no way to pass more than one command line argument to docker-compose. I also understand that I can add multiple such values into an .env file, but input in the command line is much more convenient for my use case. Any suggestions?

CodePudding user response:

The syntax:

VAR=value command ...

Isn't specific to docker-compose; that's just normal shell syntax (for setting temporary environment variables that are only visible to the specified command).

You can add as many variables as you want:

ARG1="val1" ARG2="val2" ARG3="val3" docker-compose up

These only make sense if your docker-compose.yaml references the specific variables.


A better option be to use environment files. You can use the --env-file option to docker-compose to select different environment files, so you can do something like:

docker-compose --env-file config1.env up

Or

docker-compose --env-file config2.env up
  • Related