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...

2
  • Does this answer your question? Dockerfile - set ENV to result of command Commented Jun 16, 2023 at 7:22
  • Unfortunately not as I need the $PYTHON_MAJOR_VERSION in the FROM command, not just as a regular env variable.. Commented Jun 17, 2023 at 16:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.