2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-19 05:25:33 -05:00
|
|
|
"os"
|
2015-02-14 01:01:58 -05:00
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-01-05 06:38:34 -05:00
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-16 11:50:20 -04:00
|
|
|
containerID := "testexportcontainerandimportimage"
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name", containerID, "busybox", "true")
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
out, _ := dockerCmd(c, "export", containerID)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
result := icmd.RunCmd(icmd.Cmd{
|
2017-01-05 13:08:24 -05:00
|
|
|
Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
|
|
|
|
Stdin: strings.NewReader(out),
|
2017-01-05 06:38:34 -05:00
|
|
|
})
|
|
|
|
result.Assert(c, icmd.Success)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
cleanedImageID := strings.TrimSpace(result.Combined())
|
2015-10-20 17:53:27 -04:00
|
|
|
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-12-19 05:25:33 -05:00
|
|
|
|
|
|
|
// Used to test output flag in the export command
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-16 11:50:20 -04:00
|
|
|
containerID := "testexportcontainerwithoutputandimportimage"
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name", containerID, "busybox", "true")
|
|
|
|
dockerCmd(c, "export", "--output=testexp.tar", containerID)
|
2015-04-16 11:50:20 -04:00
|
|
|
defer os.Remove("testexp.tar")
|
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
resultCat := icmd.RunCommand("cat", "testexp.tar")
|
|
|
|
resultCat.Assert(c, icmd.Success)
|
2015-03-17 03:36:56 -04:00
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
result := icmd.RunCmd(icmd.Cmd{
|
2017-01-05 13:08:24 -05:00
|
|
|
Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
|
|
|
|
Stdin: strings.NewReader(resultCat.Combined()),
|
2017-01-05 06:38:34 -05:00
|
|
|
})
|
|
|
|
result.Assert(c, icmd.Success)
|
2014-12-19 05:25:33 -05:00
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
cleanedImageID := strings.TrimSpace(result.Combined())
|
2015-10-20 17:53:27 -04:00
|
|
|
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|