github.com/damirazo/docker@v1.9.0/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/go-check/check" 9 ) 10 11 // export an image and try to import it into a new one 12 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) { 13 testRequires(c, DaemonIsLinux) 14 containerID := "testexportcontainerandimportimage" 15 16 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 17 18 out, _ := dockerCmd(c, "export", containerID) 19 20 importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") 21 importCmd.Stdin = strings.NewReader(out) 22 out, _, err := runCommandWithOutput(importCmd) 23 if err != nil { 24 c.Fatalf("failed to import image: %s, %v", out, err) 25 } 26 27 cleanedImageID := strings.TrimSpace(out) 28 if cleanedImageID == "" { 29 c.Fatalf("output should have been an image id, got: %s", out) 30 } 31 } 32 33 // Used to test output flag in the export command 34 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) { 35 testRequires(c, DaemonIsLinux) 36 containerID := "testexportcontainerwithoutputandimportimage" 37 38 dockerCmd(c, "run", "--name", containerID, "busybox", "true") 39 dockerCmd(c, "export", "--output=testexp.tar", containerID) 40 defer os.Remove("testexp.tar") 41 42 out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar")) 43 if err != nil { 44 c.Fatal(out, err) 45 } 46 47 importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") 48 importCmd.Stdin = strings.NewReader(out) 49 out, _, err = runCommandWithOutput(importCmd) 50 if err != nil { 51 c.Fatalf("failed to import image: %s, %v", out, err) 52 } 53 54 cleanedImageID := strings.TrimSpace(out) 55 if cleanedImageID == "" { 56 c.Fatalf("output should have been an image id, got: %s", out) 57 } 58 }