jjmerelo
jjmerelo

Reputation: 23537

Is there any way to introspect image values while building a container?

For instance, let's say we have this

LABEL interpreter_version="3.3.3"

We might need to get that value from inside the Dockerfile while we build it, for instance something like this

ENV PATH="/path/to/version-manager/versions/$interpreter_version/bin:$PATH"

However, LABEL values are only available from docker inspect, which is obviously not reachable from the build process. There's this proposal for container introspection, which has not been accepted, but no other way. Is there any workaround to achieve that kind of thing?

Upvotes: 2

Views: 105

Answers (1)

Adiii
Adiii

Reputation: 60046

One way is to consume from ARG instead of LABEL, as ARG considered is build time variable, you can also overide ARG at build time, where LABLE are designed for meta data.

Also, there are some guideline for using Label.

Label keys should begin and end with a lower-case letter and should only contain lower-case alphanumeric characters, the period character (.), and the hyphen character (-). Consecutive periods or hyphens are not allowed.

docker-label-guide-line

So the option is Docker build time ARG.

ARG interpreter_version="3.3.3"
ENV PATH="/path/to/version-manager/versions/$interpreter_version/bin:$PATH"

Upvotes: 2

Related Questions