github.com/rish1988/moby@v25.0.2+incompatible/daemon/images/image_exporter.go (about)

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