Skip to content

build: add multi-stage build support#31257

Merged
tonistiigi merged 4 commits intomoby:masterfrom
tonistiigi:nested-build
Mar 24, 2017
Merged

build: add multi-stage build support#31257
tonistiigi merged 4 commits intomoby:masterfrom
tonistiigi:nested-build

Conversation

@tonistiigi
Copy link
Member

@tonistiigi tonistiigi commented Feb 22, 2017

fixes #31067
fixes #31892
depends on #31236

@tonistiigi
Copy link
Member Author

@johnstep @jhowardmsft Do you know what may be the problem with windows test. TestBuildMultiStageArg passes so it shouldn't be completely broken.

@tonistiigi tonistiigi changed the title [wip] build: add multi-stage build support build: add multi-stage build support Feb 22, 2017
@tonistiigi tonistiigi added the status/failing-ci Indicates that the PR in its current state fails the test suite label Feb 22, 2017
@thaJeztah
Copy link
Member

ping @johnstep @jhowardmsft PTAL

@tonistiigi tonistiigi force-pushed the nested-build branch 3 times, most recently from d3f9f50 to cf2ac93 Compare March 7, 2017 01:29
@anusha-ragunathan
Copy link
Contributor

I tested the PR while building a lean network plugin and it works quite nicely! Design and testing LGTM.

@duglin
Copy link
Contributor

duglin commented Mar 8, 2017

A slight variant/alternative mentioned here: #31067 (comment)

Copy link
Member Author

@tonistiigi tonistiigi Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: make sure old context is closed

@tonistiigi
Copy link
Member Author

I've not rebased this since #31236 needs to be merged before anyway.

@tonistiigi
Copy link
Member Author

Based on #31067 (comment) I will reimplement this with COPY --context

@simonferquel
Copy link
Contributor

I think we need to explicitly forbid building / (or c:\) and /windows (or c:\windows) out of a Windows image. That would make the image very large, and might even fail because Windows has a concept of "exclusive openness" of files, that might make some system files not copyable

@tonistiigi tonistiigi force-pushed the nested-build branch 4 times, most recently from 88d312c to f0781af Compare March 17, 2017 23:54
@tonistiigi
Copy link
Member Author

I have updated this PR to the new COPY --context=n syntax. Named addressing should be in a separate PR.

PTAL @dnephin @dmcgowan @simonferquel @philtay

Could I move it to code-review now as the design was discussed in the previous implementations and a decision was made in the favor of this?

@philtay
Copy link

philtay commented Mar 18, 2017

Looks good. Thinking about the "zero case", I'm not sure if context=0 actually makes sense. Probably a simple COPY, without the context flag, should imply context=0. If we give to the initial context a number now (i.e. zero), we'll be forced to give it a name later for consistency (following named contexts PR). While it's easy (syntax-wise) to give the user the ability to name contexts from 1 onward, I don't see an elegant way to let them specify a name for the initial context.

Moreover it's debatable if a case like this one should really fail.

FROM busybox
COPY --context=0 foo bar

Even if we're clearly not in a nested build situation, the context=0 flag refers to the initial context. Thus, in theory, it should work. Omitting a number/name for the initial context would solve these little ambiguities and it feels (at least to me) more consistent with the actual behavior (i.e. you can COPY only from the initial context without having to specify a flag).

@tonistiigi tonistiigi removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Mar 18, 2017
@tonistiigi
Copy link
Member Author

@philtay The numbers mean the index of a build block that is defined by FROM. Accessing user files is different and doesn't require any flags. I think there is no confusion understanding that numbers start with 0. I'll change the error message to the case you pointed out so it clearly states that this copy would mean source and destination are already the same. After the naming is implemented in the next step the indexes would be minimally used anyway.

@StefanScherer
Copy link
Contributor

Great. I've seen the tweets today, but first didn't understand why people are so happy about it. After reading #31067 I understood the benefit.
Some other captains discussed about the COPY --from=0 ... as it looks very low level.
Coincidentally I've seen some slides about Rocker (https://github.com/grammarly/rocker#exportimport) and their approach how to copy artifacts from a previous layer.

FROM google/golang:1.4
ADD . /src
WORKDIR /src
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -v -o rocker.o rocker.go
EXPORT rocker.o

FROM busybox
IMPORT rocker.o /bin/rocker
CMD ["/bin/rocker"]

As we haven't seen options to Dockerfile instructions I just wonder if the final syntax could more look like this?

@StefanScherer
Copy link
Contributor

Just seen #32063, much better ❤️

@dserodio
Copy link

I'm confused, what is the syntax that was merged in this PR?

@alexisvincent
Copy link

Is it possible to run the image from a particular stage?

For instance if I have build/dev tools in a "builder" stage. That I want to use interactively.

e.g.

docker run my-image --stage=builder some-useful-binary

@dnephin
Copy link
Member

dnephin commented Jun 10, 2017

--target=

@nasirhm
Copy link

nasirhm commented Jul 27, 2020

Thank you everyone for working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARG should be scoped to FROM Proposal: Multi-stage builds