mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
delete containers during build after every step
This commit changes the way docker build cleans up containers. Containers get cleaned up right away after they've been committed and they've become an image. When the build fails, only the last container of the failing step is left behind. Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
parent
14e1a2345d
commit
7931be5cba
1 changed files with 3 additions and 3 deletions
|
@ -69,6 +69,7 @@ func (b *buildFile) clearTmp(containers map[string]struct{}) {
|
|||
if err := b.runtime.Destroy(tmp); err != nil {
|
||||
fmt.Fprintf(b.outStream, "Error removing intermediate container %s: %s\n", utils.TruncateID(c), err.Error())
|
||||
} else {
|
||||
delete(containers, c)
|
||||
fmt.Fprintf(b.outStream, "Removing intermediate container %s\n", utils.TruncateID(c))
|
||||
}
|
||||
}
|
||||
|
@ -780,14 +781,13 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
|||
}
|
||||
if err := b.BuildStep(fmt.Sprintf("%d", stepN), line); err != nil {
|
||||
return "", err
|
||||
} else if b.rm {
|
||||
b.clearTmp(b.tmpContainers)
|
||||
}
|
||||
stepN += 1
|
||||
}
|
||||
if b.image != "" {
|
||||
fmt.Fprintf(b.outStream, "Successfully built %s\n", utils.TruncateID(b.image))
|
||||
if b.rm {
|
||||
b.clearTmp(b.tmpContainers)
|
||||
}
|
||||
return b.image, nil
|
||||
}
|
||||
return "", fmt.Errorf("No image was generated. This may be because the Dockerfile does not, like, do anything.\n")
|
||||
|
|
Loading…
Add table
Reference in a new issue