0

With the support of the multi-stage builds, it has become convenient to maintain repos up to a point. But how can you extend these repos?

Up to now, you can build an image of a specific tag using the --target in the docker build command.

From docker-compose, you can use the target entry in the context entry to specify it.

In my case, I want to use an image from docker hub and extend a specific target. Right now, I am using a Dockerfile (which I call from docker-compose but that shouldn't matter) which has the

FROM repo/sample-name
DO my stuff

That repo has 3 targets in their Dockerfile named sample-name, sample-name-full which extends sample-name and sample-name-dev which extends sample-name-full. The dashes in these names are just like the repo named their targets.

What seems to be happening is that I am getting the first target as the build target (or I think I do) which is named after the repo itself. How can I, let's say, extend the intermediate target?

I tried stuff like

FROM repo/sample-name:latest-sample-name-dev

etc but I could not make it work.

Siyu
  • 11,187
  • 4
  • 43
  • 55

1 Answers1

1

This is not possible by design. One advantage of the multi-stage build is to hide intermediate stage, an example could be to download something with hard coded credentials in the first stage and then in the second stage copy the result from it. The final image, as is available on the dockerhub, is ostensibly single-stage built. Most the time you won't worry about this as the final stage has acquired all useful things from previous ones.

Siyu
  • 11,187
  • 4
  • 43
  • 55
  • So this means that what is downloaded from docker hub is an image that contains all stages, right? – I. Dimopoulos Nov 27 '18 at 14:34
  • @I.Dimopoulos it contains all layers from the last stage and some layers were built with the help of previous stages. You really don’t see previous stages, a ‘copy —from stage’ is no different than a normal copy. – Siyu Nov 27 '18 at 14:38