'Dockerfile LABEL from executable version

I am trying to label my docker image with my app version from within my Dockerfile using the LABEL command.

I can write the version into a file with the following:

RUN /opt/app/foo --version > /var/app-version

/var/app-version would now contain a plaintext file with the application version inside, ready for use in my label.

Now I need a way to place this into a docker variable/arg such that I can do something like the following:

LABEL application_version=$APP_VERSION

Or perhaps there is another way to achieve the same?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source