Docker 1.9 allows to pass arguments to a dockerfile. See link: https://docs.docker.com/engine/reference/builder/#arg
How can I pass the same arguments within docker-compose.yml?
Please provide an example too, if possible.
Docker 1.9 allows to pass arguments to a dockerfile. See link: https://docs.docker.com/engine/reference/builder/#arg
How can I pass the same arguments within docker-compose.yml?
Please provide an example too, if possible.
This feature was added in Compose 1.6.
Reference: https://docs.docker.com/compose/compose-file/#args
Now
docker-compose
supports variable substitution.Compose uses the variable values from the shell environment in which
docker-compose
is run. For example, suppose the shell containsPOSTGRES_VERSION=9.3
and you supply this configuration in yourdocker-compose.yml
file:When you run
docker-compose up
with this configuration, Compose looks for thePOSTGRES_VERSION
environment variable in the shell and substitutes its value in. For this example, Compose resolves theimage
topostgres:9.3
before running the configuration.This can now be done as of docker-compose v2+ as part of the
build
object;See the docker compose docs.
In the above example "var1" and "var2" will be sent to the build environment.
Note: any env variables (specified by using the
environment
block) which have the same name asargs
variable(s) will override that variable.