2018-03-01 17:38:34 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-04-10 10:29:48 -04:00
|
|
|
"github.com/docker/docker/internal/test/daemon"
|
2018-03-01 17:38:34 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/poll"
|
|
|
|
"gotest.tools/skip"
|
2018-03-01 17:38:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
|
|
|
func TestExportContainerAndImportImage(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-03-01 17:38:34 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-03-01 17:38:34 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, container.WithCmd("true"))
|
2018-03-01 17:38:34 -05:00
|
|
|
poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond))
|
|
|
|
|
|
|
|
reference := "repo/testexp:v1"
|
|
|
|
exportResp, err := client.ContainerExport(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-01 17:38:34 -05:00
|
|
|
importResp, err := client.ImageImport(ctx, types.ImageImportSource{
|
|
|
|
Source: exportResp,
|
|
|
|
SourceName: "-",
|
|
|
|
}, reference, types.ImageImportOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-01 17:38:34 -05:00
|
|
|
|
|
|
|
// If the import is successfully, then the message output should contain
|
|
|
|
// the image ID and match with the output from `docker images`.
|
|
|
|
|
|
|
|
dec := json.NewDecoder(importResp)
|
|
|
|
var jm jsonmessage.JSONMessage
|
|
|
|
err = dec.Decode(&jm)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-01 17:38:34 -05:00
|
|
|
|
|
|
|
images, err := client.ImageList(ctx, types.ImageListOptions{
|
|
|
|
Filters: filters.NewArgs(filters.Arg("reference", reference)),
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(jm.Status, images[0].ID))
|
2018-03-01 17:38:34 -05:00
|
|
|
}
|
2018-03-15 03:30:11 -04:00
|
|
|
|
|
|
|
// TestExportContainerAfterDaemonRestart checks that a container
|
|
|
|
// created before start of the currently running dockerd
|
|
|
|
// can be exported (as reported in #36561). To satisfy this
|
|
|
|
// condition, daemon restart is needed after container creation.
|
|
|
|
func TestExportContainerAfterDaemonRestart(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-03-15 03:30:11 -04:00
|
|
|
|
2018-04-10 10:29:48 -04:00
|
|
|
d := daemon.New(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
2018-03-15 03:30:11 -04:00
|
|
|
|
|
|
|
d.StartWithBusybox(t)
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2019-06-06 07:00:37 -04:00
|
|
|
ctrID := container.Create(ctx, t, c)
|
2018-03-15 03:30:11 -04:00
|
|
|
|
|
|
|
d.Restart(t)
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
_, err := c.ContainerExport(ctx, ctrID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-03-15 03:30:11 -04:00
|
|
|
}
|