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