From Dockerfile reference:
The
ARGinstruction defines a variable that users can pass at build-time to the builder with the docker build command using the--build-arg <varname>=<value>flag.The
ENVinstruction sets the environment variable<key>to the value<value>.
The environment variables set usingENVwill persist when a container is run from the resulting image.
So if you need build-time customization, ARG is your best choice.
If you need run-time customization (to run the same image with different settings), ENV is well-suited.
If I want to add let’s say 20 (a random number) of extensions or any other feature that can be enable|disable
Given the number of combinations involved, using ENV to set those features at runtime is best here.
But you can combine both by:
- building an image with a specific
ARG - using that
ARGas anENV
That is, with a Dockerfile including:
ARG var
ENV var=${var}
You can then either build an image with a specific var value at build-time (docker build --build-arg var=xxx), or run a container with a specific runtime value (docker run -e var=yyy)