github.com/aimxhaisse/docker@v1.6.2/daemon/export.go (about)

     1  package daemon
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/docker/docker/engine"
     7  )
     8  
     9  func (daemon *Daemon) ContainerExport(job *engine.Job) engine.Status {
    10  	if len(job.Args) != 1 {
    11  		return job.Errorf("Usage: %s container_id", job.Name)
    12  	}
    13  	name := job.Args[0]
    14  
    15  	container, err := daemon.Get(name)
    16  	if err != nil {
    17  		return job.Error(err)
    18  	}
    19  
    20  	data, err := container.Export()
    21  	if err != nil {
    22  		return job.Errorf("%s: %s", name, err)
    23  	}
    24  	defer data.Close()
    25  
    26  	// Stream the entire contents of the container (basically a volatile snapshot)
    27  	if _, err := io.Copy(job.Stdout, data); err != nil {
    28  		return job.Errorf("%s: %s", name, err)
    29  	}
    30  	// FIXME: factor job-specific LogEvent to engine.Job.Run()
    31  	container.LogEvent("export")
    32  	return engine.StatusOK
    33  }