Unsoreted Tips Regarding Dockerfiles
Dockerfile Tips
Not every ARG is created equal
When using ARG
in a Dockerfile, it is important to note that not every ARG
has the same meaning.
There are two types of ARG
:
- Build-time ARGs: These are used during the build process and are not available in the final image.
- Run-time ARGs: These are used when the container is started and are available in the final image.
Here is an example of how to use both types:
# Build-time ARGARG BUILD_VERSION=latestFROM alpine:${BUILD_VERSION}
# Run-time ARGARG RUN_VERSION=latestCMD echo "Running version: ${RUN_VERSION}"
Note that in the example above, the BUILD_VERSION
is only available to the FROM
instruction, while the RUN_VERSION
is available to the CMD
instruction.
Trying to use BUILD_VERSION
in the CMD
instruction will result in nonsense, since its value is not set at runtime and will therefore be empty.