0

I have seen a few answers about this but noone do what I would like to do, as far as I can understand. Example

If my code is able to accept different calls like this:

app.py -hist

app.py -hist -yearIni 2018 -yearEnd 2019 -station 12341234 

app.py -hist -dateIni 20-2-2018 -dateEnd 20-2-2019

And depending on what arguments it receives, it makes an API call or another.

What I want now is to dockerize this behaviour. So far I have only found Docker ARG and CMD as options, but if I understand them correctly, they do not allow to pass a file, like a yaml, specifying which arguments will appear. Instead, you are forced to somehow hard code in either Dockerfile or somewhere else the names and (possible) values of the arguments.

Since right now I have already 4-5 different combinations, and they may grow in the future, I would like to pass a file.yaml (or json or whatever other format) where I define what possible parameters can be used, and then my python code will decide whether or not those are valid parameters, and act based on that.

Pseudocode of possible yaml "schema":

predictions:
    city: "//str"
hist:
    yearIni: "//str"
    yearEnd: "//str"

    dateIni: "//str"
    dateEnd: "//str"

    station: "//str"

Is there any way to do this? To pass dynamic arguments to a python app that could work on its own with this behaviour, but now, inside docker?

monkey intern
  • 705
  • 3
  • 14
  • 34
  • You can use flags which pass arguments if you don't want to hard code values – Shardj Jun 05 '19 at 08:30
  • @Shardj Thank you for the answer. Since I am very new with Docker, would you mind pointing me to somewhere with an example? It would be of great help! – monkey intern Jun 05 '19 at 08:37
  • I'll put it in an answer – Shardj Jun 05 '19 at 08:52
  • Can you give more an example of what you're trying to do that doesn't work? A Dockerfile CMD is very easy to override. (And if your script is just a simple API client, it will probably be easier to use if it's not wrapped up in Docker.) – David Maze Jun 05 '19 at 09:50

1 Answers1

2

Here's an example of how to pass arguments to docker-compose from cli

docker-compose build --build-arg app_env=production
docker-compose up
Shardj
  • 1,800
  • 2
  • 17
  • 43