internals.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. package dockerfile
  2. // internals for handling commands. Covers many areas and a lot of
  3. // non-contiguous functionality. Please read the comments.
  4. import (
  5. "crypto/sha256"
  6. "encoding/hex"
  7. "fmt"
  8. "io"
  9. "net/http"
  10. "net/url"
  11. "os"
  12. "path/filepath"
  13. "runtime"
  14. "sort"
  15. "strings"
  16. "time"
  17. "github.com/Sirupsen/logrus"
  18. "github.com/docker/docker/api/types"
  19. "github.com/docker/docker/api/types/backend"
  20. "github.com/docker/docker/api/types/container"
  21. "github.com/docker/docker/api/types/strslice"
  22. "github.com/docker/docker/builder"
  23. "github.com/docker/docker/builder/dockerfile/parser"
  24. "github.com/docker/docker/builder/remotecontext"
  25. "github.com/docker/docker/pkg/httputils"
  26. "github.com/docker/docker/pkg/ioutils"
  27. "github.com/docker/docker/pkg/jsonmessage"
  28. "github.com/docker/docker/pkg/progress"
  29. "github.com/docker/docker/pkg/streamformatter"
  30. "github.com/docker/docker/pkg/stringid"
  31. "github.com/docker/docker/pkg/system"
  32. "github.com/docker/docker/pkg/urlutil"
  33. "github.com/pkg/errors"
  34. )
  35. func (b *Builder) commit(comment string) error {
  36. if b.disableCommit {
  37. return nil
  38. }
  39. if !b.hasFromImage() {
  40. return errors.New("Please provide a source image with `from` prior to commit")
  41. }
  42. // TODO: why is this set here?
  43. b.runConfig.Image = b.image
  44. runConfigWithCommentCmd := copyRunConfig(b.runConfig, withCmdComment(comment))
  45. hit, err := b.probeCache(b.image, runConfigWithCommentCmd)
  46. if err != nil || hit {
  47. return err
  48. }
  49. id, err := b.create(runConfigWithCommentCmd)
  50. if err != nil {
  51. return err
  52. }
  53. return b.commitContainer(id, b.runConfig)
  54. }
  55. func (b *Builder) commitContainer(id string, runConfig *container.Config) error {
  56. if b.disableCommit {
  57. return nil
  58. }
  59. commitCfg := &backend.ContainerCommitConfig{
  60. ContainerCommitConfig: types.ContainerCommitConfig{
  61. Author: b.maintainer,
  62. Pause: true,
  63. Config: runConfig,
  64. },
  65. }
  66. // Commit the container
  67. imageID, err := b.docker.Commit(id, commitCfg)
  68. if err != nil {
  69. return err
  70. }
  71. // TODO: this function should return imageID and runConfig instead of setting
  72. // then on the builder
  73. b.image = imageID
  74. b.imageContexts.update(imageID, runConfig)
  75. return nil
  76. }
  77. type copyInfo struct {
  78. root string
  79. path string
  80. hash string
  81. decompress bool
  82. }
  83. func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalDecompression bool, cmdName string, imageSource *imageMount) error {
  84. if len(args) < 2 {
  85. return fmt.Errorf("Invalid %s format - at least two arguments required", cmdName)
  86. }
  87. // Work in daemon-specific filepath semantics
  88. dest := filepath.FromSlash(args[len(args)-1]) // last one is always the dest
  89. b.runConfig.Image = b.image
  90. var infos []copyInfo
  91. // Loop through each src file and calculate the info we need to
  92. // do the copy (e.g. hash value if cached). Don't actually do
  93. // the copy until we've looked at all src files
  94. var err error
  95. for _, orig := range args[0 : len(args)-1] {
  96. if urlutil.IsURL(orig) {
  97. if !allowRemote {
  98. return fmt.Errorf("Source can't be a URL for %s", cmdName)
  99. }
  100. remote, path, err := b.download(orig)
  101. if err != nil {
  102. return err
  103. }
  104. defer os.RemoveAll(remote.Root())
  105. h, err := remote.Hash(path)
  106. if err != nil {
  107. return err
  108. }
  109. infos = append(infos, copyInfo{
  110. root: remote.Root(),
  111. path: path,
  112. hash: h,
  113. })
  114. continue
  115. }
  116. // not a URL
  117. subInfos, err := b.calcCopyInfo(cmdName, orig, allowLocalDecompression, true, imageSource)
  118. if err != nil {
  119. return err
  120. }
  121. infos = append(infos, subInfos...)
  122. }
  123. if len(infos) == 0 {
  124. return errors.New("No source files were specified")
  125. }
  126. if len(infos) > 1 && !strings.HasSuffix(dest, string(os.PathSeparator)) {
  127. return fmt.Errorf("When using %s with more than one source file, the destination must be a directory and end with a /", cmdName)
  128. }
  129. // For backwards compat, if there's just one info then use it as the
  130. // cache look-up string, otherwise hash 'em all into one
  131. var srcHash string
  132. if len(infos) == 1 {
  133. info := infos[0]
  134. srcHash = info.hash
  135. } else {
  136. var hashs []string
  137. var origs []string
  138. for _, info := range infos {
  139. origs = append(origs, info.path)
  140. hashs = append(hashs, info.hash)
  141. }
  142. hasher := sha256.New()
  143. hasher.Write([]byte(strings.Join(hashs, ",")))
  144. srcHash = "multi:" + hex.EncodeToString(hasher.Sum(nil))
  145. }
  146. cmd := b.runConfig.Cmd
  147. // TODO: should this have been using origPaths instead of srcHash in the comment?
  148. b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) %s %s in %s ", cmdName, srcHash, dest)))
  149. defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
  150. // TODO: this should pass a copy of runConfig
  151. if hit, err := b.probeCache(b.image, b.runConfig); err != nil || hit {
  152. return err
  153. }
  154. container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
  155. Config: b.runConfig,
  156. // Set a log config to override any default value set on the daemon
  157. HostConfig: &container.HostConfig{LogConfig: defaultLogConfig},
  158. })
  159. if err != nil {
  160. return err
  161. }
  162. b.tmpContainers[container.ID] = struct{}{}
  163. // Twiddle the destination when it's a relative path - meaning, make it
  164. // relative to the WORKINGDIR
  165. if dest, err = normaliseDest(cmdName, b.runConfig.WorkingDir, dest); err != nil {
  166. return err
  167. }
  168. for _, info := range infos {
  169. if err := b.docker.CopyOnBuild(container.ID, dest, info.root, info.path, info.decompress); err != nil {
  170. return err
  171. }
  172. }
  173. return b.commitContainer(container.ID, copyRunConfig(b.runConfig, withCmd(cmd)))
  174. }
  175. type runConfigModifier func(*container.Config)
  176. func copyRunConfig(runConfig *container.Config, modifiers ...runConfigModifier) *container.Config {
  177. copy := *runConfig
  178. for _, modifier := range modifiers {
  179. modifier(&copy)
  180. }
  181. return &copy
  182. }
  183. func withCmd(cmd []string) runConfigModifier {
  184. return func(runConfig *container.Config) {
  185. runConfig.Cmd = cmd
  186. }
  187. }
  188. func withCmdComment(comment string) runConfigModifier {
  189. return func(runConfig *container.Config) {
  190. runConfig.Cmd = append(getShell(runConfig), "#(nop) ", comment)
  191. }
  192. }
  193. func withEnv(env []string) runConfigModifier {
  194. return func(runConfig *container.Config) {
  195. runConfig.Env = env
  196. }
  197. }
  198. // getShell is a helper function which gets the right shell for prefixing the
  199. // shell-form of RUN, ENTRYPOINT and CMD instructions
  200. func getShell(c *container.Config) []string {
  201. if 0 == len(c.Shell) {
  202. return append([]string{}, defaultShell[:]...)
  203. }
  204. return append([]string{}, c.Shell[:]...)
  205. }
  206. func (b *Builder) download(srcURL string) (remote builder.Source, p string, err error) {
  207. // get filename from URL
  208. u, err := url.Parse(srcURL)
  209. if err != nil {
  210. return
  211. }
  212. path := filepath.FromSlash(u.Path) // Ensure in platform semantics
  213. if strings.HasSuffix(path, string(os.PathSeparator)) {
  214. path = path[:len(path)-1]
  215. }
  216. parts := strings.Split(path, string(os.PathSeparator))
  217. filename := parts[len(parts)-1]
  218. if filename == "" {
  219. err = fmt.Errorf("cannot determine filename from url: %s", u)
  220. return
  221. }
  222. // Initiate the download
  223. resp, err := httputils.Download(srcURL)
  224. if err != nil {
  225. return
  226. }
  227. // Prepare file in a tmp dir
  228. tmpDir, err := ioutils.TempDir("", "docker-remote")
  229. if err != nil {
  230. return
  231. }
  232. defer func() {
  233. if err != nil {
  234. os.RemoveAll(tmpDir)
  235. }
  236. }()
  237. tmpFileName := filepath.Join(tmpDir, filename)
  238. tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
  239. if err != nil {
  240. return
  241. }
  242. progressOutput := streamformatter.NewJSONProgressOutput(b.Output, true)
  243. progressReader := progress.NewProgressReader(resp.Body, progressOutput, resp.ContentLength, "", "Downloading")
  244. // Download and dump result to tmp file
  245. // TODO: add filehash directly
  246. if _, err = io.Copy(tmpFile, progressReader); err != nil {
  247. tmpFile.Close()
  248. return
  249. }
  250. fmt.Fprintln(b.Stdout)
  251. // Set the mtime to the Last-Modified header value if present
  252. // Otherwise just remove atime and mtime
  253. mTime := time.Time{}
  254. lastMod := resp.Header.Get("Last-Modified")
  255. if lastMod != "" {
  256. // If we can't parse it then just let it default to 'zero'
  257. // otherwise use the parsed time value
  258. if parsedMTime, err := http.ParseTime(lastMod); err == nil {
  259. mTime = parsedMTime
  260. }
  261. }
  262. tmpFile.Close()
  263. if err = system.Chtimes(tmpFileName, mTime, mTime); err != nil {
  264. return
  265. }
  266. lc, err := remotecontext.NewLazyContext(tmpDir)
  267. if err != nil {
  268. return
  269. }
  270. return lc, filename, nil
  271. }
  272. var windowsBlacklist = map[string]bool{
  273. "c:\\": true,
  274. "c:\\windows": true,
  275. }
  276. func (b *Builder) calcCopyInfo(cmdName, origPath string, allowLocalDecompression, allowWildcards bool, imageSource *imageMount) ([]copyInfo, error) {
  277. // Work in daemon-specific OS filepath semantics
  278. origPath = filepath.FromSlash(origPath)
  279. // validate windows paths from other images
  280. if imageSource != nil && runtime.GOOS == "windows" {
  281. p := strings.ToLower(filepath.Clean(origPath))
  282. if !filepath.IsAbs(p) {
  283. if filepath.VolumeName(p) != "" {
  284. if p[len(p)-2:] == ":." { // case where clean returns weird c:. paths
  285. p = p[:len(p)-1]
  286. }
  287. p += "\\"
  288. } else {
  289. p = filepath.Join("c:\\", p)
  290. }
  291. }
  292. if _, blacklisted := windowsBlacklist[p]; blacklisted {
  293. return nil, errors.New("copy from c:\\ or c:\\windows is not allowed on windows")
  294. }
  295. }
  296. if origPath != "" && origPath[0] == os.PathSeparator && len(origPath) > 1 {
  297. origPath = origPath[1:]
  298. }
  299. origPath = strings.TrimPrefix(origPath, "."+string(os.PathSeparator))
  300. source := b.source
  301. var err error
  302. if imageSource != nil {
  303. source, err = imageSource.context()
  304. if err != nil {
  305. return nil, err
  306. }
  307. }
  308. if source == nil {
  309. return nil, errors.Errorf("No context given. Impossible to use %s", cmdName)
  310. }
  311. // Deal with wildcards
  312. if allowWildcards && containsWildcards(origPath) {
  313. var copyInfos []copyInfo
  314. if err := filepath.Walk(source.Root(), func(path string, info os.FileInfo, err error) error {
  315. if err != nil {
  316. return err
  317. }
  318. rel, err := remotecontext.Rel(source.Root(), path)
  319. if err != nil {
  320. return err
  321. }
  322. if rel == "." {
  323. return nil
  324. }
  325. if match, _ := filepath.Match(origPath, rel); !match {
  326. return nil
  327. }
  328. // Note we set allowWildcards to false in case the name has
  329. // a * in it
  330. subInfos, err := b.calcCopyInfo(cmdName, rel, allowLocalDecompression, false, imageSource)
  331. if err != nil {
  332. return err
  333. }
  334. copyInfos = append(copyInfos, subInfos...)
  335. return nil
  336. }); err != nil {
  337. return nil, err
  338. }
  339. return copyInfos, nil
  340. }
  341. // Must be a dir or a file
  342. hash, err := source.Hash(origPath)
  343. if err != nil {
  344. return nil, err
  345. }
  346. fi, err := remotecontext.StatAt(source, origPath)
  347. if err != nil {
  348. return nil, err
  349. }
  350. // TODO: remove, handle dirs in Hash()
  351. copyInfos := []copyInfo{{root: source.Root(), path: origPath, hash: hash, decompress: allowLocalDecompression}}
  352. if imageSource != nil {
  353. // fast-cache based on imageID
  354. if h, ok := b.imageContexts.getCache(imageSource.id, origPath); ok {
  355. copyInfos[0].hash = h.(string)
  356. return copyInfos, nil
  357. }
  358. }
  359. // Deal with the single file case
  360. if !fi.IsDir() {
  361. copyInfos[0].hash = "file:" + copyInfos[0].hash
  362. return copyInfos, nil
  363. }
  364. fp, err := remotecontext.FullPath(source, origPath)
  365. if err != nil {
  366. return nil, err
  367. }
  368. // Must be a dir
  369. var subfiles []string
  370. err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
  371. if err != nil {
  372. return err
  373. }
  374. rel, err := remotecontext.Rel(source.Root(), path)
  375. if err != nil {
  376. return err
  377. }
  378. if rel == "." {
  379. return nil
  380. }
  381. hash, err := source.Hash(rel)
  382. if err != nil {
  383. return nil
  384. }
  385. // we already checked handleHash above
  386. subfiles = append(subfiles, hash)
  387. return nil
  388. })
  389. if err != nil {
  390. return nil, err
  391. }
  392. sort.Strings(subfiles)
  393. hasher := sha256.New()
  394. hasher.Write([]byte(strings.Join(subfiles, ",")))
  395. copyInfos[0].hash = "dir:" + hex.EncodeToString(hasher.Sum(nil))
  396. if imageSource != nil {
  397. b.imageContexts.setCache(imageSource.id, origPath, copyInfos[0].hash)
  398. }
  399. return copyInfos, nil
  400. }
  401. func (b *Builder) processImageFrom(img builder.Image) error {
  402. if img != nil {
  403. b.image = img.ImageID()
  404. if img.RunConfig() != nil {
  405. b.runConfig = img.RunConfig()
  406. }
  407. }
  408. // Check to see if we have a default PATH, note that windows won't
  409. // have one as it's set by HCS
  410. if system.DefaultPathEnv != "" {
  411. if _, ok := b.runConfigEnvMapping()["PATH"]; !ok {
  412. b.runConfig.Env = append(b.runConfig.Env,
  413. "PATH="+system.DefaultPathEnv)
  414. }
  415. }
  416. if img == nil {
  417. // Typically this means they used "FROM scratch"
  418. return nil
  419. }
  420. // Process ONBUILD triggers if they exist
  421. if nTriggers := len(b.runConfig.OnBuild); nTriggers != 0 {
  422. word := "trigger"
  423. if nTriggers > 1 {
  424. word = "triggers"
  425. }
  426. fmt.Fprintf(b.Stderr, "# Executing %d build %s...\n", nTriggers, word)
  427. }
  428. // Copy the ONBUILD triggers, and remove them from the config, since the config will be committed.
  429. onBuildTriggers := b.runConfig.OnBuild
  430. b.runConfig.OnBuild = []string{}
  431. // Reset stdin settings as all build actions run without stdin
  432. b.runConfig.OpenStdin = false
  433. b.runConfig.StdinOnce = false
  434. // parse the ONBUILD triggers by invoking the parser
  435. for _, step := range onBuildTriggers {
  436. result, err := parser.Parse(strings.NewReader(step))
  437. if err != nil {
  438. return err
  439. }
  440. for _, n := range result.AST.Children {
  441. if err := checkDispatch(n); err != nil {
  442. return err
  443. }
  444. upperCasedCmd := strings.ToUpper(n.Value)
  445. switch upperCasedCmd {
  446. case "ONBUILD":
  447. return errors.New("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
  448. case "MAINTAINER", "FROM":
  449. return errors.Errorf("%s isn't allowed as an ONBUILD trigger", upperCasedCmd)
  450. }
  451. }
  452. if err := dispatchFromDockerfile(b, result); err != nil {
  453. return err
  454. }
  455. }
  456. return nil
  457. }
  458. // probeCache checks if cache match can be found for current build instruction.
  459. // If an image is found, probeCache returns `(true, nil)`.
  460. // If no image is found, it returns `(false, nil)`.
  461. // If there is any error, it returns `(false, err)`.
  462. func (b *Builder) probeCache(imageID string, runConfig *container.Config) (bool, error) {
  463. c := b.imageCache
  464. if c == nil || b.options.NoCache || b.cacheBusted {
  465. return false, nil
  466. }
  467. cache, err := c.GetCache(imageID, runConfig)
  468. if err != nil {
  469. return false, err
  470. }
  471. if len(cache) == 0 {
  472. logrus.Debugf("[BUILDER] Cache miss: %s", runConfig.Cmd)
  473. b.cacheBusted = true
  474. return false, nil
  475. }
  476. fmt.Fprint(b.Stdout, " ---> Using cache\n")
  477. logrus.Debugf("[BUILDER] Use cached version: %s", runConfig.Cmd)
  478. b.image = string(cache)
  479. b.imageContexts.update(b.image, runConfig)
  480. return true, nil
  481. }
  482. func (b *Builder) create(runConfig *container.Config) (string, error) {
  483. if !b.hasFromImage() {
  484. return "", errors.New("Please provide a source image with `from` prior to run")
  485. }
  486. resources := container.Resources{
  487. CgroupParent: b.options.CgroupParent,
  488. CPUShares: b.options.CPUShares,
  489. CPUPeriod: b.options.CPUPeriod,
  490. CPUQuota: b.options.CPUQuota,
  491. CpusetCpus: b.options.CPUSetCPUs,
  492. CpusetMems: b.options.CPUSetMems,
  493. Memory: b.options.Memory,
  494. MemorySwap: b.options.MemorySwap,
  495. Ulimits: b.options.Ulimits,
  496. }
  497. // TODO: why not embed a hostconfig in builder?
  498. hostConfig := &container.HostConfig{
  499. SecurityOpt: b.options.SecurityOpt,
  500. Isolation: b.options.Isolation,
  501. ShmSize: b.options.ShmSize,
  502. Resources: resources,
  503. NetworkMode: container.NetworkMode(b.options.NetworkMode),
  504. // Set a log config to override any default value set on the daemon
  505. LogConfig: defaultLogConfig,
  506. ExtraHosts: b.options.ExtraHosts,
  507. }
  508. // Create the container
  509. c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
  510. Config: runConfig,
  511. HostConfig: hostConfig,
  512. })
  513. if err != nil {
  514. return "", err
  515. }
  516. for _, warning := range c.Warnings {
  517. fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
  518. }
  519. b.tmpContainers[c.ID] = struct{}{}
  520. fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID))
  521. // override the entry point that may have been picked up from the base image
  522. if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, runConfig.Cmd); err != nil {
  523. return "", err
  524. }
  525. return c.ID, nil
  526. }
  527. var errCancelled = errors.New("build cancelled")
  528. func (b *Builder) run(cID string) (err error) {
  529. attached := make(chan struct{})
  530. errCh := make(chan error)
  531. go func() {
  532. errCh <- b.docker.ContainerAttachRaw(cID, nil, b.Stdout, b.Stderr, true, attached)
  533. }()
  534. select {
  535. case err := <-errCh:
  536. return err
  537. case <-attached:
  538. }
  539. finished := make(chan struct{})
  540. cancelErrCh := make(chan error, 1)
  541. go func() {
  542. select {
  543. case <-b.clientCtx.Done():
  544. logrus.Debugln("Build cancelled, killing and removing container:", cID)
  545. b.docker.ContainerKill(cID, 0)
  546. b.removeContainer(cID)
  547. cancelErrCh <- errCancelled
  548. case <-finished:
  549. cancelErrCh <- nil
  550. }
  551. }()
  552. if err := b.docker.ContainerStart(cID, nil, "", ""); err != nil {
  553. close(finished)
  554. if cancelErr := <-cancelErrCh; cancelErr != nil {
  555. logrus.Debugf("Build cancelled (%v) and got an error from ContainerStart: %v",
  556. cancelErr, err)
  557. }
  558. return err
  559. }
  560. // Block on reading output from container, stop on err or chan closed
  561. if err := <-errCh; err != nil {
  562. close(finished)
  563. if cancelErr := <-cancelErrCh; cancelErr != nil {
  564. logrus.Debugf("Build cancelled (%v) and got an error from errCh: %v",
  565. cancelErr, err)
  566. }
  567. return err
  568. }
  569. if ret, _ := b.docker.ContainerWait(cID, -1); ret != 0 {
  570. close(finished)
  571. if cancelErr := <-cancelErrCh; cancelErr != nil {
  572. logrus.Debugf("Build cancelled (%v) and got a non-zero code from ContainerWait: %d",
  573. cancelErr, ret)
  574. }
  575. // TODO: change error type, because jsonmessage.JSONError assumes HTTP
  576. return &jsonmessage.JSONError{
  577. Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", strings.Join(b.runConfig.Cmd, " "), ret),
  578. Code: ret,
  579. }
  580. }
  581. close(finished)
  582. return <-cancelErrCh
  583. }
  584. func (b *Builder) removeContainer(c string) error {
  585. rmConfig := &types.ContainerRmConfig{
  586. ForceRemove: true,
  587. RemoveVolume: true,
  588. }
  589. if err := b.docker.ContainerRm(c, rmConfig); err != nil {
  590. fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
  591. return err
  592. }
  593. return nil
  594. }
  595. func (b *Builder) clearTmp() {
  596. for c := range b.tmpContainers {
  597. if err := b.removeContainer(c); err != nil {
  598. return
  599. }
  600. delete(b.tmpContainers, c)
  601. fmt.Fprintf(b.Stdout, "Removing intermediate container %s\n", stringid.TruncateID(c))
  602. }
  603. }