for the dockerfile ->
ARG PYTHON_VERSION=3.12
FROM python:$PYTHON_VERSION-slim
RUN echo $PYTHON_VERSION
the build ->
docker build --progress=plain --no-cache
show ->
#5 [XXX 2/2] RUN echo 3.12.8
#5 0.200 3.12.8
why the ARG change from 3.12 to to 3.12.8 and can I disable it ?
for the dockerfile ->
ARG PYTHON_VERSION=3.12
FROM python:$PYTHON_VERSION-slim
RUN echo $PYTHON_VERSION
the build ->
docker build --progress=plain --no-cache
show ->
#5 [XXX 2/2] RUN echo 3.12.8
#5 0.200 3.12.8
why the ARG change from 3.12 to to 3.12.8 and can I disable it ?
Build args are scoped to either the remaining steps of the defined stage, or when specified at the top of the Dockerfile to only the global scope (the FROM
lines, and not any of the steps within a build stage).
So there is no PYTHON_VERSION
arg within the stage, and docker falls back to using environment variables defined in the selected image:
$ docker inspect python:3.12-slim
[
{
...
"Config": {
...
"Env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305",
"PYTHON_VERSION=3.12.8",
"PYTHON_SHA256=c909157bb25ec114e5869124cc2a9c4a4d4c1e957ca4ff553f1edc692101154e"
],
...
},
...
To reuse the build arg within the stage, you can define the arg again there:
ARG PYTHON_VERSION=3.12
FROM python:$PYTHON_VERSION-slim
ARG PYTHON_VERSION
RUN echo $PYTHON_VERSION