mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-04 20:51:44 +00: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:
+3
-3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user