0

I have a simple Dockerfile:

ARG PYTHON_VERSION

FROM python:${PYTHON_VERSION}

If I do something like export PYTHON_VERSION=3.11 and sudo docker build --build-arg PYTHON_VERSION ., Docker returns an invalid reference format error. On the other hand, sudo docker build --build-arg PYTHON_VERSION=$PYTHON_VERSION . works as intended.

This seems contradictory to Docker's documentation:

You may also use the --build-arg flag without a value, in which case the value from the local environment will be propagated into the Docker container being built:

export HTTP_PROXY=http://10.20.30.2:1234

docker build --build-arg HTTP_PROXY .

The version of docker I'm using is 20.10.23. What's wrong here?

AmagicalFishy
  • 1,249
  • 1
  • 12
  • 36
  • 1
    `sudo` won't use the current environment variables by default, see this question https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo – Iain Shelvington Feb 01 '23 at 00:46
  • @IainShelvington Hah!!! That's it. I forgot `sudo` doesn't propagate environments. Thanks :D – AmagicalFishy Feb 01 '23 at 00:49

0 Answers0