0

I have a Dockerfile that receives a PYTHON_VERSION ARG. I need both the full version for and the major versions only for FROM commands. Something like this:

ARG PYTHON_VERSION  # assume 3.10.10

FROM gcr.io/something/image:${PYTHON_VERSION}
...
FROM gcr.io/something_else/image:{PYTHON_MAJOR_VERSION}

In bash I can easily extract this with sed -En 's/^([0-9]+[.][0-9]+).*/\1/p' (and probably million other options). Can I do something similar in Dockerfile? Either running a regex (but the output should go to a variable), or assign the output of a RUN command to a variable?

I'm currently using two ARGs but that seems stupid...

Zach Moshe
  • 2,782
  • 4
  • 24
  • 40
  • Does this answer your question? [Dockerfile - set ENV to result of command](https://stackoverflow.com/questions/34911622/dockerfile-set-env-to-result-of-command) – Paolo Jun 16 '23 at 07:22
  • Unfortunately not as I need the $PYTHON_MAJOR_VERSION in the FROM command, not just as a regular env variable.. – Zach Moshe Jun 17 '23 at 16:05

0 Answers0