2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2015-02-14 01:01:58 -05:00
|
|
|
"strings"
|
2014-02-25 11:17:48 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
|
|
|
func TestExportContainerAndImportImage(t *testing.T) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
|
|
|
out, _, err = runCommandWithOutput(inspectCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err)
|
|
|
|
}
|
|
|
|
|
2015-02-14 01:01:58 -05:00
|
|
|
exportCmd := exec.Command(dockerBinary, "export", cleanedContainerID)
|
2014-10-14 15:25:46 -04:00
|
|
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
|
|
|
t.Fatalf("failed to export container: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-02-14 01:01:58 -05:00
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
2014-10-14 15:25:46 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to import image: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", cleanedImageID)
|
2014-10-14 15:25:46 -04:00
|
|
|
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
|
|
|
t.Fatalf("output should've been an image id: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2014-04-03 20:22:32 -04:00
|
|
|
deleteContainer(cleanedContainerID)
|
2014-08-26 03:03:38 -04:00
|
|
|
deleteImages("repo/testexp:v1")
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
logDone("export - export a container")
|
|
|
|
logDone("import - import an image")
|
|
|
|
}
|