image_exporter.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package images // import "github.com/docker/docker/daemon/images"
  2. import (
  3. "context"
  4. "io"
  5. "github.com/containerd/log"
  6. "github.com/docker/docker/container"
  7. "github.com/docker/docker/image/tarexport"
  8. )
  9. // ExportImage exports a list of images to the given output stream. The
  10. // exported images are archived into a tar when written to the output
  11. // stream. All images with the given tag and all versions containing
  12. // the same tag are exported. names is the set of tags to export, and
  13. // outStream is the writer which the images are written to.
  14. func (i *ImageService) ExportImage(ctx context.Context, names []string, outStream io.Writer) error {
  15. imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
  16. return imageExporter.Save(names, outStream)
  17. }
  18. func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Container, fn func(root string) error) error {
  19. rwlayer, err := i.layerStore.GetRWLayer(c.ID)
  20. if err != nil {
  21. return err
  22. }
  23. defer func() {
  24. if err != nil {
  25. err2 := i.ReleaseLayer(rwlayer)
  26. if err2 != nil {
  27. log.G(ctx).WithError(err2).WithField("container", c.ID).Warn("Failed to release layer")
  28. }
  29. }
  30. }()
  31. basefs, err := rwlayer.Mount(c.GetMountLabel())
  32. if err != nil {
  33. return err
  34. }
  35. return fn(basefs)
  36. }
  37. // LoadImage uploads a set of images into the repository. This is the
  38. // complement of ExportImage. The input stream is an uncompressed tar
  39. // ball containing images and metadata.
  40. func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
  41. imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
  42. return imageExporter.Load(inTar, outStream, quiet)
  43. }