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

- 816
- 1
- 10
- 16
-
I don't really understand the question - in docker-compose you put your arguments in the docker-compose.yml file. Is there a problem with that approach for you? – Adrian Mouat Apr 19 '15 at 15:42
-
@AdrianMouat Yes it's not ideal because everytime you want to send a new option you have to modify the docker-compose.yml, rebuild and rerun. I would like to be able to send options to my program when I run the service as I am able to do when I run the main container with `docker run` and use ENTRYPOINT in my Dockerfile in order to achieve this behaviour. – Donovan Apr 20 '15 at 06:51
3 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.

- 44,585
- 16
- 110
- 102
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.

- 1,262,500
- 529
- 4,410
- 5,250
-
3Isn't there any way to put the ARGS into the docker-compose file? Passing them on the command line is too volatile in my case. – dsteinkopf Mar 09 '16 at 06:46
-
1@dsteinkopf Sure: with 'command' (https://docs.docker.com/compose/compose-file/#command) you can override the image default command, allowing you to repeat the command defined in the image, but change its parameters. – VonC Mar 09 '16 at 06:50
You need to look at the Dockerfile and see what is handling the APP_OPTIONS. Chances are that the ENTRYPOINT is taking the option flags. In this case, specify the command to send to the entrypoint using
command: [-flag1, -flag2]
This works because the COMMAND in the Dockerfile acts as default args to the entrypoint when both are specified https://www.ctl.io/developers/blog/post/dockerfile-entrypoint-vs-cmd/

- 128
- 4