2014-02-26 00:17:48 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2014-12-19 18:25:33 +08:00
|
|
|
"os"
|
2014-02-26 00:17:48 +08:00
|
|
|
"os/exec"
|
2015-02-14 14:01:58 +08:00
|
|
|
"strings"
|
2015-04-19 00:46:47 +08:00
|
|
|
|
2015-10-21 05:53:27 +08:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-19 00:46:47 +08:00
|
|
|
"github.com/go-check/check"
|
2014-02-26 00:17:48 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
2015-04-19 00:46:47 +08:00
|
|
|
func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
2015-08-29 01:36:42 +08:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-16 23:50:20 +08:00
|
|
|
containerID := "testexportcontainerandimportimage"
|
|
|
|
|
|
2015-07-20 14:55:40 +08:00
|
|
|
dockerCmd(c, "run", "--name", containerID, "busybox", "true")
|
2014-02-26 00:17:48 +08:00
|
|
|
|
2015-07-20 14:55:40 +08:00
|
|
|
out, _ := dockerCmd(c, "export", containerID)
|
2014-02-26 00:17:48 +08:00
|
|
|
|
2015-02-14 14:01:58 +08:00
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2015-07-20 14:55:40 +08:00
|
|
|
out, _, err := runCommandWithOutput(importCmd)
|
2015-10-21 05:53:27 +08:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out))
|
2014-02-26 00:17:48 +08:00
|
|
|
|
2015-04-06 21:21:18 +08:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2015-10-21 05:53:27 +08:00
|
|
|
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
|
2014-02-26 00:17:48 +08:00
|
|
|
}
|
2014-12-19 18:25:33 +08:00
|
|
|
|
|
|
|
|
// Used to test output flag in the export command
|
2015-04-19 00:46:47 +08:00
|
|
|
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
|
2015-08-29 01:36:42 +08:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-16 23:50:20 +08:00
|
|
|
containerID := "testexportcontainerwithoutputandimportimage"
|
|
|
|
|
|
2015-07-20 14:55:40 +08:00
|
|
|
dockerCmd(c, "run", "--name", containerID, "busybox", "true")
|
|
|
|
|
dockerCmd(c, "export", "--output=testexp.tar", containerID)
|
2015-04-16 23:50:20 +08:00
|
|
|
defer os.Remove("testexp.tar")
|
|
|
|
|
|
2015-07-20 14:55:40 +08:00
|
|
|
out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar"))
|
2015-10-21 05:53:27 +08:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2015-03-17 15:36:56 +08:00
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-12-19 18:25:33 +08:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
2015-10-21 05:53:27 +08:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out))
|
2014-12-19 18:25:33 +08:00
|
|
|
|
2015-04-06 21:21:18 +08:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2015-10-21 05:53:27 +08:00
|
|
|
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
|
2014-12-19 18:25:33 +08:00
|
|
|
}
|