mirror of https://github.com/docker/docs.git
Decouple daemon and container to export containers.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
9f79cfdb2f
commit
1c94f5f53a
|
@ -356,30 +356,6 @@ func (container *Container) Resize(h, w int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) export() (archive.Archive, error) {
|
|
||||||
if err := container.Mount(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
uidMaps, gidMaps := container.daemon.GetUIDGIDMaps()
|
|
||||||
archive, err := archive.TarWithOptions(container.basefs, &archive.TarOptions{
|
|
||||||
Compression: archive.Uncompressed,
|
|
||||||
UIDMaps: uidMaps,
|
|
||||||
GIDMaps: gidMaps,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
container.Unmount()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
arch := ioutils.NewReadCloserWrapper(archive, func() error {
|
|
||||||
err := archive.Close()
|
|
||||||
container.Unmount()
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
container.logEvent("export")
|
|
||||||
return arch, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount sets container.basefs
|
// Mount sets container.basefs
|
||||||
func (container *Container) Mount() error {
|
func (container *Container) Mount() error {
|
||||||
return container.daemon.Mount(container)
|
return container.daemon.Mount(container)
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
derr "github.com/docker/docker/errors"
|
derr "github.com/docker/docker/errors"
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerExport writes the contents of the container to the given
|
// ContainerExport writes the contents of the container to the given
|
||||||
|
@ -14,7 +16,7 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := container.export()
|
data, err := daemon.containerExport(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return derr.ErrorCodeExportFailed.WithArgs(name, err)
|
return derr.ErrorCodeExportFailed.WithArgs(name, err)
|
||||||
}
|
}
|
||||||
|
@ -26,3 +28,27 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) containerExport(container *Container) (archive.Archive, error) {
|
||||||
|
if err := daemon.Mount(container); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
uidMaps, gidMaps := daemon.GetUIDGIDMaps()
|
||||||
|
archive, err := archive.TarWithOptions(container.basefs, &archive.TarOptions{
|
||||||
|
Compression: archive.Uncompressed,
|
||||||
|
UIDMaps: uidMaps,
|
||||||
|
GIDMaps: gidMaps,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
daemon.unmount(container)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
arch := ioutils.NewReadCloserWrapper(archive, func() error {
|
||||||
|
err := archive.Close()
|
||||||
|
container.Unmount()
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
daemon.logContainerEvent(container, "export")
|
||||||
|
return arch, err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue