I am trying to use docker-compose up
the way you can use docker run [APP_CONTAINER_NAME] [APP_OPTIONS]
.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With