Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass argument to docker compose

In my docker compose file there is a dynamic field which I'd like to generate during the running. Actually it is a string template:

environment:     - SERVER_URL:https://0.0.0.0:${PORT} 

And I want to configure this PORT parameter dynamically

docker-compose run <service> PORT=443 

In documentation there is ARGS parameters set I suppose I can use. But there is no information how can I use those inside compose file

like image 909
deeptowncitizen Avatar asked Apr 21 '17 13:04

deeptowncitizen


People also ask

How do I pass ARGs to ENTRYPOINT Docker?

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. And the URL you pass in the run command will be appended to the ENTRYPOINT script. In this case, CMD instruction is not required in the Dockerfile.

How do I pass environment variables to Docker containers?

With a Command Line Argument The command used to launch Docker containers, docker run , accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env , and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...


2 Answers

In docker-compose, arguments are available and usefull only in dockerfile. You can specify what you are doing in the level ahead like following:

#dockerfile ARG PORT ENV SERVER_URL "https://0.0.0.0:$PORT" 

Your port can be set in your docker-compose.yml:

build:   context: .   args:     - PORT=443 

It is actually an environment variable in any case. You can pass it through your run command if that fits to you:

PORT=443 docker-compose run <service> #or docker-compose run <service> -e PORT=443 
like image 74
dzof31 Avatar answered Sep 29 '22 09:09

dzof31


You can use the flag when using docker-compose build

docker-compose build --build-arg PRODUCTION=VALUE 

In Dockerfile you can get the argument PRODUCTION

# Dockerfile ARG PRODUCTION FROM node:latest 
like image 25
blueandhack Avatar answered Sep 29 '22 09:09

blueandhack