Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send command line options to my dockerized program that I start with "docker-compose up"?

I am trying to use docker-compose up the way you can use docker run [APP_CONTAINER_NAME] [APP_OPTIONS].

like image 743
Donovan Avatar asked Apr 19 '15 11:04

Donovan


People also ask

How do I pass an environment variable in docker run?

When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.

How do I run a command against a docker container?

If you need to run a command inside a running Docker container, but don't need any interactivity, use the docker exec command without any flags: docker exec container-name tail /var/log/date.


2 Answers

The point of Docker Compose is that you don't have to remember all your command line switches.

If you want to change environment variables for different contexts, I suggest you create a base common.yml file for Compose. You can then create a new yml file for each different context, inheriting from the common.yml file with the extends instruction. You can then use the -f flag to docker compose to switch between contexts.

Also note that Compose should not "rebuild" anything if you just change a variable in the yml, and that you can use an external file for environment variables if that works better for you.

like image 176
Adrian Mouat Avatar answered Oct 19 '22 05:10

Adrian Mouat


docker run is defined as:

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

While docker compose run is defined as:

docker-compose run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]

In both cases, the final ARGS (which could be the "APP_OPTIONS" of the OP's question) will be passed to the container command.

Note that some of the docker run option can be used as is in docker-compose run (lie a -d, to run the container command detached), but not all of them.

like image 43
VonC Avatar answered Oct 19 '22 03:10

VonC