2014-08-01 00:29:38 +04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2015-09-18 20:48:16 +03:00
|
|
|
|
2015-09-11 01:01:18 +03:00
|
|
|
"github.com/docker/docker/context"
|
2015-09-18 20:48:16 +03:00
|
|
|
derr "github.com/docker/docker/errors"
|
2014-08-01 00:29:38 +04:00
|
|
|
)
|
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
// ContainerExport writes the contents of the container to the given
|
|
|
|
// writer. An error is returned if the container cannot be found.
|
2015-09-11 01:01:18 +03:00
|
|
|
func (daemon *Daemon) ContainerExport(ctx context.Context, name string, out io.Writer) error {
|
|
|
|
container, err := daemon.Get(ctx, name)
|
2014-12-17 02:06:35 +03:00
|
|
|
if err != nil {
|
2015-03-25 10:44:12 +03:00
|
|
|
return err
|
2014-08-01 00:29:38 +04:00
|
|
|
}
|
2014-12-17 02:06:35 +03:00
|
|
|
|
2015-09-11 01:01:18 +03:00
|
|
|
data, err := container.export(ctx)
|
2014-12-17 02:06:35 +03:00
|
|
|
if err != nil {
|
2015-09-18 20:48:16 +03:00
|
|
|
return derr.ErrorCodeExportFailed.WithArgs(name, err)
|
2014-12-17 02:06:35 +03:00
|
|
|
}
|
|
|
|
defer data.Close()
|
|
|
|
|
|
|
|
// Stream the entire contents of the container (basically a volatile snapshot)
|
2015-04-12 17:04:01 +03:00
|
|
|
if _, err := io.Copy(out, data); err != nil {
|
2015-09-18 20:48:16 +03:00
|
|
|
return derr.ErrorCodeExportFailed.WithArgs(name, err)
|
2014-12-17 02:06:35 +03:00
|
|
|
}
|
2015-03-25 10:44:12 +03:00
|
|
|
return nil
|
2014-08-01 00:29:38 +04:00
|
|
|
}
|