docker_cli_export_import_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "os"
  4. "os/exec"
  5. "strings"
  6. "github.com/go-check/check"
  7. )
  8. // export an image and try to import it into a new one
  9. func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
  10. containerID := "testexportcontainerandimportimage"
  11. dockerCmd(c, "run", "--name", containerID, "busybox", "true")
  12. out, _ := dockerCmd(c, "export", containerID)
  13. importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
  14. importCmd.Stdin = strings.NewReader(out)
  15. out, _, err := runCommandWithOutput(importCmd)
  16. if err != nil {
  17. c.Fatalf("failed to import image: %s, %v", out, err)
  18. }
  19. cleanedImageID := strings.TrimSpace(out)
  20. if cleanedImageID == "" {
  21. c.Fatalf("output should have been an image id, got: %s", out)
  22. }
  23. }
  24. // Used to test output flag in the export command
  25. func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
  26. containerID := "testexportcontainerwithoutputandimportimage"
  27. dockerCmd(c, "run", "--name", containerID, "busybox", "true")
  28. dockerCmd(c, "export", "--output=testexp.tar", containerID)
  29. defer os.Remove("testexp.tar")
  30. out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar"))
  31. if err != nil {
  32. c.Fatal(out, err)
  33. }
  34. importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
  35. importCmd.Stdin = strings.NewReader(out)
  36. out, _, err = runCommandWithOutput(importCmd)
  37. if err != nil {
  38. c.Fatalf("failed to import image: %s, %v", out, err)
  39. }
  40. cleanedImageID := strings.TrimSpace(out)
  41. if cleanedImageID == "" {
  42. c.Fatalf("output should have been an image id, got: %s", out)
  43. }
  44. }