I have 20-30 variables I need to pass to dockerfile for building an image.
I can see the following options:
#1. use ARGs
- easy to set defaults as ARG param=default_value
- easy to pass non-default values as --build-arg
- each ARG is processed creating and removing an intermediate container, what at least takes time
- each ARG should be specified again after each FROM, need to declare many duplicated ARGs, cannot set one global ARG.
#2. use ENV
- faster, all ENVs can be set once and not processed via intermediate container for each of them
- not obvious how and where to set defaults, not as easy as in case of ARGs
- in order to to pass non-default values I would need to set environment variables before calling build, instead of passing --build-arg
- all the env variables will exist in the image and whereas they only needed on the building stage
#3. build docker file on fly from a template by a shell script, replacing parameters on the values there
- faster, no need to declare duplicate ARGs
- extra logic, complicates the process
Am I missing anything?
What option would you prefer?