github.com/tompao/docker@v1.9.1/daemon/export.go (about)

     1  package daemon
     2  
     3  import (
     4  	"io"
     5  
     6  	derr "github.com/docker/docker/errors"
     7  )
     8  
     9  // ContainerExport writes the contents of the container to the given
    10  // writer. An error is returned if the container cannot be found.
    11  func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
    12  	container, err := daemon.Get(name)
    13  	if err != nil {
    14  		return err
    15  	}
    16  
    17  	data, err := container.export()
    18  	if err != nil {
    19  		return derr.ErrorCodeExportFailed.WithArgs(name, err)
    20  	}
    21  	defer data.Close()
    22  
    23  	// Stream the entire contents of the container (basically a volatile snapshot)
    24  	if _, err := io.Copy(out, data); err != nil {
    25  		return derr.ErrorCodeExportFailed.WithArgs(name, err)
    26  	}
    27  	return nil
    28  }