Given this Dockerfile:
ARG PY_VERSION
FROM python:${PY_VERSION}-buster
CMD python -V
This docker build . --build-arg PY_VERSION=3.8
and this PY_VERSION=3.8 docker build . --build-arg PY_VERSION
work.
But this
PY_VERSION=3.8
echo $PY_VERSION
3.8
docker build . --build-arg PY_VERSION
Sending build context to Docker daemon 2.048kB
Step 1/3 : ARG PY_VERSION
Step 2/3 : FROM python:${PY_VERSION}-buster
invalid reference format
Why doesn't docker pick up the env variable if it's not set in the same line?
versions:
Docker version 19.03.5, build 633a0ea
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin19.0.0)
Edit:
I'm aware that I can use docker build . --build-arg PY_VERSION=$PY_VERSION
, just wondering why the example I provided does not work