1

I suspect the answer to this question is no as the FROM command comes first in the file (before any ENV statements), but can you parameterize the version of the base image that a docker container is created from?

e.g.

FROM image-name:4.6.${patchVersion}

The reason that I am looking at this is to support CI/CD. I have separated the build container and the deployment container, and the patchVersion of the deployment container is generated by the build. I would also like to generate the patch number of the build container this way, and then reference this from the deployment container

1

TL;DR not only with Docker

Long:

The documentation says:

Environment variables are supported by the following list of instructions in the Dockerfile:

  • ADD
  • COPY
  • ENV
  • EXPOSE
  • LABEL
  • USER
  • WORKDIR
  • VOLUME
  • STOPSIGNAL

https://docs.docker.com/engine/reference/builder/#environment-replacement

You can use envsubst https://linux.die.net/man/1/envsubst to rewrite your Dockerfile before doing the docker build

envsubst < Dockerfile.template_with_variable > Dockerfile
docker build .

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.