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

3

9

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

Epiglottis answered 19/4, 2015 at 11:57 Comment(2)
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?Venose
@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.Epiglottis
V
3

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.

Venose answered 20/4, 2015 at 7:59 Comment(0)
Z
2

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.

Zilpah answered 19/4, 2015 at 13:38 Comment(2)
Isn'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.Arnettaarnette
@Arnettaarnette Sure: with 'command' (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.Zilpah
W
2

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/

Whenever answered 9/2, 2017 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.