Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments within docker-compose?

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.

like image 263
meallhour Avatar asked Dec 16 '15 21:12

meallhour


People also ask

How do I pass ARGs in docker run?

Just add the full ab command at the end of the docker run command. It will override the whole CMD specified in the Dockerfile. So if you want to pass the URL argument to ENTRYPOINT, you need to pass the URL alone. The reason is we have the ab command as part of the ENTRYPOINT definition.

How do I pass ARGs to Dockerfile build?

If you want to pass multiple build arguments with docker build command you have to pass each argument with separate — build-arg. docker build -t <image-name>:<tag> --build-arg <key1>=<value1> --build-arg <key2>=<value2> .

Does Docker compose pass environment variables?

Docker Compose allows us to pass environment variables in via command line or to define them in our shell. However, it's best to keep these values inside the actual Compose file and out of the command line.


1 Answers

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 contains POSTGRES_VERSION=9.3 and you supply this configuration in your docker-compose.yml file:

db:   image: "postgres:${POSTGRES_VERSION}" 

When you run docker-compose up with this configuration, Compose looks for the POSTGRES_VERSION environment variable in the shell and substitutes its value in. For this example, Compose resolves the image to postgres:9.3 before running the configuration.

like image 190
Hemerson Varela Avatar answered Sep 29 '22 14:09

Hemerson Varela