github.com/hms58/moby@v1.13.1/integration-cli/docker_cli_export_import_test.go (about) 1 package main 2 3 import ( 4 "os" 5 "os/exec" 6 "strings" 7 8 "github.com/docker/docker/pkg/integration/checker" 9 "github.com/go-check/check" 10 ) 11 12 // export an image and try to import it into a new one 13 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) { 14 testRequires(c, DaemonIsLinux) 15 containerID := "testexportcontainerandimportimage" 16 17 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 18 19 out, _ := dockerCmd(c, "export", containerID) 20 21 importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") 22 importCmd.Stdin = strings.NewReader(out) 23 out, _, err := runCommandWithOutput(importCmd) 24 c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) 25 26 cleanedImageID := strings.TrimSpace(out) 27 c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) 28 } 29 30 // Used to test output flag in the export command 31 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) { 32 testRequires(c, DaemonIsLinux) 33 containerID := "testexportcontainerwithoutputandimportimage" 34 35 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 36 dockerCmd(c, "export", "--output=testexp.tar", containerID) 37 defer os.Remove("testexp.tar") 38 39 out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar")) 40 c.Assert(err, checker.IsNil, check.Commentf(out)) 41 42 importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") 43 importCmd.Stdin = strings.NewReader(out) 44 out, _, err = runCommandWithOutput(importCmd) 45 c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) 46 47 cleanedImageID := strings.TrimSpace(out) 48 c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) 49 }