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