diff --git a/api/types/client.go b/api/types/client.go index 1a2ac62c4e..36ed5cc29d 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -43,13 +43,6 @@ type ContainerLogsOptions struct { Details bool } -// ContainerRemoveOptions holds parameters to remove containers. -type ContainerRemoveOptions struct { - RemoveVolumes bool - RemoveLinks bool - Force bool -} - // ContainerStartOptions holds parameters to start containers. type ContainerStartOptions struct { CheckpointID string diff --git a/api/types/container/options.go b/api/types/container/options.go index 08feae26b8..56ed925d42 100644 --- a/api/types/container/options.go +++ b/api/types/container/options.go @@ -27,3 +27,10 @@ type CommitOptions struct { Pause bool Config *Config } + +// RemoveOptions holds parameters to remove containers. +type RemoveOptions struct { + RemoveVolumes bool + RemoveLinks bool + Force bool +} diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index 36bad7e56f..a528097ea8 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -109,6 +109,11 @@ type ContainerAttachOptions = container.AttachOptions // Deprecated: use [container.CommitOptions]. type ContainerCommitOptions = container.CommitOptions +// ContainerRemoveOptions holds parameters to remove containers. +// +// Deprecated: use [container.RemoveOptions]. +type ContainerRemoveOptions = container.RemoveOptions + // DecodeSecurityOptions decodes a security options string slice to a type safe // [system.SecurityOpt]. // diff --git a/client/container_remove.go b/client/container_remove.go index c21de609b0..39f7b106a1 100644 --- a/client/container_remove.go +++ b/client/container_remove.go @@ -4,11 +4,11 @@ import ( "context" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // ContainerRemove kills and removes a container from the docker host. -func (cli *Client) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error { +func (cli *Client) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error { query := url.Values{} if options.RemoveVolumes { query.Set("v", "1") diff --git a/client/container_remove_test.go b/client/container_remove_test.go index 333ad16d0d..eecbd71268 100644 --- a/client/container_remove_test.go +++ b/client/container_remove_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -19,7 +19,7 @@ func TestContainerRemoveError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) + err := client.ContainerRemove(context.Background(), "container_id", container.RemoveOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } @@ -27,7 +27,7 @@ func TestContainerRemoveNotFoundError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusNotFound, "no such container: container_id")), } - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) + err := client.ContainerRemove(context.Background(), "container_id", container.RemoveOptions{}) assert.Check(t, is.ErrorContains(err, "no such container: container_id")) assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) } @@ -59,7 +59,7 @@ func TestContainerRemove(t *testing.T) { }), } - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{ + err := client.ContainerRemove(context.Background(), "container_id", container.RemoveOptions{ RemoveVolumes: true, Force: true, }) diff --git a/client/interface.go b/client/interface.go index 189afccc89..712e925e5b 100644 --- a/client/interface.go +++ b/client/interface.go @@ -62,7 +62,7 @@ type ContainerAPIClient interface { ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) ContainerPause(ctx context.Context, container string) error - ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error + ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error ContainerRename(ctx context.Context, container, newContainerName string) error ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 04758d5490..72dc6d3cfe 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1089,7 +1089,7 @@ func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) { assert.NilError(c, err) defer apiClient.Close() - err = apiClient.ContainerRemove(testutil.GetContext(c), id, types.ContainerRemoveOptions{}) + err = apiClient.ContainerRemove(testutil.GetContext(c), id, container.RemoveOptions{}) assert.NilError(c, err) } @@ -1098,7 +1098,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteNotExist(c *testing.T) { assert.NilError(c, err) defer apiClient.Close() - err = apiClient.ContainerRemove(testutil.GetContext(c), "doesnotexist", types.ContainerRemoveOptions{}) + err = apiClient.ContainerRemove(testutil.GetContext(c), "doesnotexist", container.RemoveOptions{}) assert.ErrorContains(c, err, "No such container: doesnotexist") } @@ -1107,7 +1107,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) { id := strings.TrimSpace(out) assert.NilError(c, waitRun(id)) - removeOptions := types.ContainerRemoveOptions{ + removeOptions := container.RemoveOptions{ Force: true, } @@ -1135,7 +1135,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) { links := inspectFieldJSON(c, id2, "HostConfig.Links") assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers") - removeOptions := types.ContainerRemoveOptions{ + removeOptions := container.RemoveOptions{ RemoveLinks: true, } @@ -1168,7 +1168,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) { _, err = os.Stat(source) assert.NilError(c, err) - removeOptions := types.ContainerRemoveOptions{ + removeOptions := container.RemoveOptions{ Force: true, RemoveVolumes: true, } @@ -1549,7 +1549,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) { assert.NilError(c, err) defer apiClient.Close() - err = apiClient.ContainerRemove(testutil.GetContext(c), "", types.ContainerRemoveOptions{}) + err = apiClient.ContainerRemove(testutil.GetContext(c), "", container.RemoveOptions{}) assert.Check(c, errdefs.IsNotFound(err)) } @@ -2116,7 +2116,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) { assert.NilError(c, err) poll.WaitOn(c, containerExit(ctx, apiclient, ctr.ID), poll.WithDelay(time.Second)) - err = apiclient.ContainerRemove(ctx, ctr.ID, types.ContainerRemoveOptions{ + err = apiclient.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{ RemoveVolumes: true, Force: true, }) diff --git a/integration/container/cdi_test.go b/integration/container/cdi_test.go index 2a803488e8..9c8b249ce3 100644 --- a/integration/container/cdi_test.go +++ b/integration/container/cdi_test.go @@ -38,7 +38,7 @@ func TestCreateWithCDIDevices(t *testing.T) { container.WithCmd("/bin/sh", "-c", "env"), container.WithCDIDevices("vendor1.com/device=foo"), ) - defer apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + defer apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) inspect, err := apiClient.ContainerInspect(ctx, id) assert.NilError(t, err) diff --git a/integration/container/create_test.go b/integration/container/create_test.go index d585c59a79..fed5980a97 100644 --- a/integration/container/create_test.go +++ b/integration/container/create_test.go @@ -436,7 +436,7 @@ func TestCreateTmpfsOverrideAnonymousVolume(t *testing.T) { ) defer func() { - err := apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + err := apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) }() diff --git a/integration/container/daemon_linux_test.go b/integration/container/daemon_linux_test.go index ef22f0706f..8f5f6f84e9 100644 --- a/integration/container/daemon_linux_test.go +++ b/integration/container/daemon_linux_test.go @@ -47,7 +47,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) { c := d.NewClientT(t) cID := container.Create(ctx, t, c) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) err := c.ContainerStart(ctx, cID, types.ContainerStartOptions{}) assert.Check(t, err, "error starting test container") @@ -105,7 +105,7 @@ func TestDaemonRestartIpcMode(t *testing.T) { container.WithCmd("top"), container.WithRestartPolicy(containertypes.RestartPolicyAlways), ) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) inspect, err := c.ContainerInspect(ctx, cID) assert.NilError(t, err) @@ -121,7 +121,7 @@ func TestDaemonRestartIpcMode(t *testing.T) { // check a new container is created with shareable ipc mode as per new daemon default cID = container.Run(ctx, t, c) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) inspect, err = c.ContainerInspect(ctx, cID) assert.NilError(t, err) @@ -156,7 +156,7 @@ func TestDaemonHostGatewayIP(t *testing.T) { inspect, err := c.NetworkInspect(ctx, "bridge", types.NetworkInspectOptions{}) assert.NilError(t, err) assert.Check(t, is.Contains(res.Stdout(), inspect.IPAM.Config[0].Gateway)) - c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) d.Stop(t) // Verify the IP in /etc/hosts is same as host-gateway-ip @@ -169,7 +169,7 @@ func TestDaemonHostGatewayIP(t *testing.T) { assert.Assert(t, is.Len(res.Stderr(), 0)) assert.Equal(t, 0, res.ExitCode) assert.Check(t, is.Contains(res.Stdout(), "6.7.8.9")) - c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) d.Stop(t) } diff --git a/integration/container/daemon_test.go b/integration/container/daemon_test.go index 4aeb2e3fd8..0ae1b384e1 100644 --- a/integration/container/daemon_test.go +++ b/integration/container/daemon_test.go @@ -3,7 +3,7 @@ package container import ( "testing" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/testutil" "github.com/docker/docker/testutil/daemon" @@ -35,7 +35,7 @@ func TestContainerKillOnDaemonStart(t *testing.T) { // Sadly this means the test will take longer, but at least this test can be parallelized. id := container.Run(ctx, t, apiClient, container.WithCmd("/bin/sh", "-c", "while true; do echo hello; sleep 1; done")) defer func() { - err := apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + err := apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) }() diff --git a/integration/container/logs_test.go b/integration/container/logs_test.go index 7bf95c1567..171f5b7055 100644 --- a/integration/container/logs_test.go +++ b/integration/container/logs_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/daemon/logger/jsonfilelog" "github.com/docker/docker/daemon/logger/local" "github.com/docker/docker/integration/internal/container" @@ -136,7 +137,7 @@ func testLogs(t *testing.T, logDriver string) { container.WithTty(tty), container.WithLogDriver(logDriver), ) - defer apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + defer apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) poll.WaitOn(t, container.IsStopped(ctx, apiClient, id), poll.WithDelay(time.Millisecond*100), diff --git a/integration/container/mounts_linux_test.go b/integration/container/mounts_linux_test.go index 13bf138c2a..49f6019943 100644 --- a/integration/container/mounts_linux_test.go +++ b/integration/container/mounts_linux_test.go @@ -192,7 +192,7 @@ func TestMountDaemonRoot(t *testing.T) { } defer func() { - if err := apiClient.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true}); err != nil { + if err := apiClient.ContainerRemove(ctx, c.ID, containertypes.RemoveOptions{Force: true}); err != nil { panic(err) } }() diff --git a/integration/container/remove_test.go b/integration/container/remove_test.go index e6bcf90c4d..519e7b5ab2 100644 --- a/integration/container/remove_test.go +++ b/integration/container/remove_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" @@ -42,7 +42,7 @@ func TestRemoveContainerWithRemovedVolume(t *testing.T) { err := os.RemoveAll(tempDir.Path()) assert.NilError(t, err) - err = apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ + err = apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{ RemoveVolumes: true, }) assert.NilError(t, err) @@ -67,7 +67,7 @@ func TestRemoveContainerWithVolume(t *testing.T) { assert.Check(t, is.Equal(1, len(insp.Mounts))) volName := insp.Mounts[0].Name - err = apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ + err = apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{ RemoveVolumes: true, }) assert.NilError(t, err) @@ -85,7 +85,7 @@ func TestRemoveContainerRunning(t *testing.T) { cID := container.Run(ctx, t, apiClient) - err := apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{}) + err := apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsConflict)) assert.Check(t, is.ErrorContains(err, "container is running")) } @@ -96,7 +96,7 @@ func TestRemoveContainerForceRemoveRunning(t *testing.T) { cID := container.Run(ctx, t, apiClient) - err := apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ + err := apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{ Force: true, }) assert.NilError(t, err) @@ -106,7 +106,7 @@ func TestRemoveInvalidContainer(t *testing.T) { ctx := setupTest(t) apiClient := testEnv.APIClient() - err := apiClient.ContainerRemove(ctx, "unknown", types.ContainerRemoveOptions{}) + err := apiClient.ContainerRemove(ctx, "unknown", containertypes.RemoveOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) assert.Check(t, is.ErrorContains(err, "No such container")) } diff --git a/integration/container/rename_test.go b/integration/container/rename_test.go index 5345dc6d8e..c9c1a1b63d 100644 --- a/integration/container/rename_test.go +++ b/integration/container/rename_test.go @@ -36,7 +36,7 @@ func TestRenameLinkedContainer(t *testing.T) { container.Run(ctx, t, apiClient, container.WithName(aName)) - err = apiClient.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true}) + err = apiClient.ContainerRemove(ctx, bID, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) bID = container.Run(ctx, t, apiClient, container.WithName(bName), container.WithLinks(aName)) diff --git a/integration/container/restart_test.go b/integration/container/restart_test.go index c3324c3f2e..19fb06c832 100644 --- a/integration/container/restart_test.go +++ b/integration/container/restart_test.go @@ -102,7 +102,7 @@ func TestDaemonRestartKillContainers(t *testing.T) { resp, err := apiClient.ContainerCreate(ctx, tc.config, tc.hostConfig, nil, nil, "") assert.NilError(t, err) - defer apiClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true}) + defer apiClient.ContainerRemove(ctx, resp.ID, container.RemoveOptions{Force: true}) if tc.xStart { err = apiClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) @@ -192,7 +192,7 @@ func TestContainerWithAutoRemoveCanBeRestarted(t *testing.T) { testContainer.WithAutoRemove, ) defer func() { - err := apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + err := apiClient.ContainerRemove(ctx, cID, container.RemoveOptions{Force: true}) if t.Failed() && err != nil { t.Logf("Cleaning up test container failed with error: %v", err) } diff --git a/integration/container/run_linux_test.go b/integration/container/run_linux_test.go index 89308d816a..5ebacdc948 100644 --- a/integration/container/run_linux_test.go +++ b/integration/container/run_linux_test.go @@ -297,7 +297,7 @@ func TestMacAddressIsAppliedToMainNetworkWithShortID(t *testing.T) { container.WithStopSignal("SIGKILL"), container.WithNetworkMode(n[:10]), container.WithMacAddress("02:42:08:26:a9:55")) - defer container.Remove(ctx, t, apiClient, cid, types.ContainerRemoveOptions{Force: true}) + defer container.Remove(ctx, t, apiClient, cid, containertypes.RemoveOptions{Force: true}) c := container.Inspect(ctx, t, apiClient, cid) assert.Equal(t, c.NetworkSettings.Networks["testnet"].MacAddress, "02:42:08:26:a9:55") diff --git a/integration/container/wait_test.go b/integration/container/wait_test.go index 0a0abee504..082ef49b1b 100644 --- a/integration/container/wait_test.go +++ b/integration/container/wait_test.go @@ -210,7 +210,7 @@ func TestWaitRestartedContainer(t *testing.T) { containerID := container.Run(ctx, t, cli, container.WithCmd("sh", "-c", "trap 'exit 5' SIGTERM; while true; do sleep 0.1; done"), ) - defer cli.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{Force: true}) + defer cli.ContainerRemove(ctx, containerID, containertypes.RemoveOptions{Force: true}) // Container is running now, wait for exit waitResC, errC := cli.ContainerWait(ctx, containerID, tc.waitCond) diff --git a/integration/daemon/daemon_test.go b/integration/daemon/daemon_test.go index 394d75c87c..d052fb4a04 100644 --- a/integration/daemon/daemon_test.go +++ b/integration/daemon/daemon_test.go @@ -410,7 +410,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) { Target: "/foo", } cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"), container.WithRestartPolicy(policy)) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) // Stop the daemon d.Restart(t, "--live-restore", "--iptables=false") @@ -452,7 +452,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) { const testContent = "hello" cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("sh", "-c", "echo "+testContent+">>/foo/test.txt; sleep infinity")) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) // Wait until container creates a file in the volume. poll.WaitOn(t, func(t poll.LogT) poll.Result { @@ -484,7 +484,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) { // Check if a new container with the same volume has access to the previous content. // This fails if the volume gets unmounted at startup. cID2 := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("cat", "/foo/test.txt")) - defer c.ContainerRemove(ctx, cID2, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID2, containertypes.RemoveOptions{Force: true}) poll.WaitOn(t, container.IsStopped(ctx, c, cID2)) @@ -505,7 +505,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) { }) // Remove that container which should free the references in the volume - err = c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + err = c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) // Now we should be able to remove the volume @@ -524,11 +524,11 @@ func testLiveRestoreVolumeReferences(t *testing.T) { Target: "/foo", } cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top")) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) d.Restart(t, "--live-restore", "--iptables=false") - err := c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + err := c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) }) } diff --git a/integration/image/save_test.go b/integration/image/save_test.go index 186140e3e3..da506ee02e 100644 --- a/integration/image/save_test.go +++ b/integration/image/save_test.go @@ -107,7 +107,7 @@ func TestSaveRepoWithMultipleImages(t *testing.T) { res, err := client.ContainerCommit(ctx, id, containertypes.CommitOptions{Reference: tag}) assert.NilError(t, err) - err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + err = client.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) assert.NilError(t, err) return res.ID diff --git a/integration/internal/container/container.go b/integration/internal/container/container.go index 950fa2f73c..fb22b3de55 100644 --- a/integration/internal/container/container.go +++ b/integration/internal/container/container.go @@ -155,7 +155,7 @@ func demultiplexStreams(ctx context.Context, resp types.HijackedResponse) (strea return s, err } -func Remove(ctx context.Context, t *testing.T, apiClient client.APIClient, container string, options types.ContainerRemoveOptions) { +func Remove(ctx context.Context, t *testing.T, apiClient client.APIClient, container string, options container.RemoveOptions) { t.Helper() err := apiClient.ContainerRemove(ctx, container, options) diff --git a/integration/network/dns_test.go b/integration/network/dns_test.go index ac3b13b493..1231051e7b 100644 --- a/integration/network/dns_test.go +++ b/integration/network/dns_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/network" "github.com/docker/docker/testutil" @@ -29,7 +29,7 @@ func TestDaemonDNSFallback(t *testing.T) { defer c.NetworkRemove(ctx, "test") cid := container.Run(ctx, t, c, container.WithNetworkMode("test"), container.WithCmd("nslookup", "docker.com")) - defer c.ContainerRemove(ctx, cid, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cid, containertypes.RemoveOptions{Force: true}) poll.WaitOn(t, container.IsSuccessful(ctx, c, cid), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(10*time.Second)) } diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 4e6687d4df..154c08d931 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" ntypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/network" @@ -37,14 +38,14 @@ func TestRunContainerWithBridgeNone(t *testing.T) { c := d.NewClientT(t) id1 := container.Run(ctx, t, c) - defer c.ContainerRemove(ctx, id1, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, id1, containertypes.RemoveOptions{Force: true}) result, err := container.Exec(ctx, c, id1, []string{"ip", "l"}) assert.NilError(t, err) assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled") id2 := container.Run(ctx, t, c, container.WithNetworkMode("bridge")) - defer c.ContainerRemove(ctx, id2, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, id2, containertypes.RemoveOptions{Force: true}) result, err = container.Exec(ctx, c, id2, []string{"ip", "l"}) assert.NilError(t, err) @@ -58,7 +59,7 @@ func TestRunContainerWithBridgeNone(t *testing.T) { assert.NilError(t, err, "Failed to get current process network namespace: %+v", err) id3 := container.Run(ctx, t, c, container.WithNetworkMode("host")) - defer c.ContainerRemove(ctx, id3, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, id3, containertypes.RemoveOptions{Force: true}) result, err = container.Exec(ctx, c, id3, []string{"sh", "-c", nsCommand}) assert.NilError(t, err) @@ -250,7 +251,7 @@ func TestDefaultNetworkOpts(t *testing.T) { // Start a container to inspect the MTU of its network interface id1 := container.Run(ctx, t, c, container.WithNetworkMode(networkName)) - defer c.ContainerRemove(ctx, id1, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, id1, containertypes.RemoveOptions{Force: true}) result, err := container.Exec(ctx, c, id1, []string{"ip", "l", "show", "eth0"}) assert.NilError(t, err) diff --git a/integration/plugin/authz/authz_plugin_test.go b/integration/plugin/authz/authz_plugin_test.go index 6bf5135199..bfedc0606a 100644 --- a/integration/plugin/authz/authz_plugin_test.go +++ b/integration/plugin/authz/authz_plugin_test.go @@ -18,6 +18,7 @@ import ( "time" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" eventtypes "github.com/docker/docker/api/types/events" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" @@ -387,7 +388,7 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) { c := d.NewClientT(t) cID := container.Run(ctx, t, c) - defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true}) _, err = f.Seek(0, io.SeekStart) assert.NilError(t, err) diff --git a/integration/plugin/graphdriver/external_test.go b/integration/plugin/graphdriver/external_test.go index 5d56555510..1c74f123de 100644 --- a/integration/plugin/graphdriver/external_test.go +++ b/integration/plugin/graphdriver/external_test.go @@ -461,7 +461,7 @@ func testGraphDriver(ctx context.Context, t *testing.T, c client.APIClient, driv Path: "/hello", }), "diffs: %v", diffs) - err = c.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ + err = c.ContainerRemove(ctx, id, containertypes.RemoveOptions{ Force: true, }) assert.NilError(t, err) diff --git a/integration/plugin/logging/logging_linux_test.go b/integration/plugin/logging/logging_linux_test.go index f74e6c41e5..49a27c51c2 100644 --- a/integration/plugin/logging/logging_linux_test.go +++ b/integration/plugin/logging/logging_linux_test.go @@ -47,7 +47,7 @@ func TestContinueAfterPluginCrash(t *testing.T) { ), ) cancel() - defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) + defer client.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) // Attach to the container to make sure it's written a few times to stdout attach, err := client.ContainerAttach(ctx, id, containertypes.AttachOptions{Stream: true, Stdout: true}) diff --git a/integration/plugin/logging/read_test.go b/integration/plugin/logging/read_test.go index a80c4634de..b28af7d96d 100644 --- a/integration/plugin/logging/read_test.go +++ b/integration/plugin/logging/read_test.go @@ -60,7 +60,7 @@ func TestReadPluginNoRead(t *testing.T) { "", ) assert.Assert(t, err) - defer client.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true}) + defer client.ContainerRemove(ctx, c.ID, container.RemoveOptions{Force: true}) err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{}) assert.Assert(t, err) diff --git a/integration/system/cgroupdriver_systemd_test.go b/integration/system/cgroupdriver_systemd_test.go index c011e9f1d6..6479d84a72 100644 --- a/integration/system/cgroupdriver_systemd_test.go +++ b/integration/system/cgroupdriver_systemd_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/testutil" "github.com/docker/docker/testutil/daemon" @@ -45,7 +46,7 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) { ctrID := container.Create(ctx, t, c, func(ctr *container.TestContainerConfig) { ctr.HostConfig.Resources.Memory = mem }) - defer c.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true}) + defer c.ContainerRemove(ctx, ctrID, containertypes.RemoveOptions{Force: true}) err := c.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}) assert.NilError(t, err) diff --git a/integration/volume/volume_test.go b/integration/volume/volume_test.go index 6de70e3f26..da0b065178 100644 --- a/integration/volume/volume_test.go +++ b/integration/volume/volume_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" clientpkg "github.com/docker/docker/client" @@ -84,7 +84,7 @@ func TestVolumesRemove(t *testing.T) { }) t.Run("volume not in use", func(t *testing.T) { - err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ + err = client.ContainerRemove(ctx, id, containertypes.RemoveOptions{ Force: true, }) assert.NilError(t, err) @@ -135,7 +135,7 @@ func TestVolumesRemoveSwarmEnabled(t *testing.T) { }) t.Run("volume not in use", func(t *testing.T) { - err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ + err = client.ContainerRemove(ctx, id, containertypes.RemoveOptions{ Force: true, }) assert.NilError(t, err) @@ -321,7 +321,7 @@ VOLUME ` + volDest img := build.Do(ctx, t, client, fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))) id := container.Create(ctx, t, client, container.WithImage(img)) - defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}) + defer client.ContainerRemove(ctx, id, containertypes.RemoveOptions{}) inspect, err := client.ContainerInspect(ctx, id) assert.NilError(t, err) @@ -331,7 +331,7 @@ VOLUME ` + volDest volumeName := inspect.Mounts[0].Name assert.Assert(t, volumeName != "") - err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}) + err = client.ContainerRemove(ctx, id, containertypes.RemoveOptions{}) assert.NilError(t, err) pruneReport, err := client.VolumesPrune(ctx, filters.Args{}) diff --git a/testutil/environment/clean.go b/testutil/environment/clean.go index 8e591ba05e..6893de7b01 100644 --- a/testutil/environment/clean.go +++ b/testutil/environment/clean.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" @@ -43,9 +44,9 @@ func unpauseAllContainers(ctx context.Context, t testing.TB, client client.Conta t.Helper() containers := getPausedContainers(ctx, t, client) if len(containers) > 0 { - for _, container := range containers { - err := client.ContainerUnpause(ctx, container.ID) - assert.Check(t, err, "failed to unpause container %s", container.ID) + for _, ctr := range containers { + err := client.ContainerUnpause(ctx, ctr.ID) + assert.Check(t, err, "failed to unpause container %s", ctr.ID) } } } @@ -69,18 +70,18 @@ func deleteAllContainers(ctx context.Context, t testing.TB, apiclient client.Con return } - for _, container := range containers { - if _, ok := protectedContainers[container.ID]; ok { + for _, ctr := range containers { + if _, ok := protectedContainers[ctr.ID]; ok { continue } - err := apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{ + err := apiclient.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{ Force: true, RemoveVolumes: true, }) if err == nil || errdefs.IsNotFound(err) || alreadyExists.MatchString(err.Error()) || isErrNotFoundSwarmClassic(err) { continue } - assert.Check(t, err, "failed to remove %s", container.ID) + assert.Check(t, err, "failed to remove %s", ctr.ID) } } diff --git a/testutil/fakestorage/storage.go b/testutil/fakestorage/storage.go index ae7c2a862a..75f429c93c 100644 --- a/testutil/fakestorage/storage.go +++ b/testutil/fakestorage/storage.go @@ -125,7 +125,7 @@ func (f *remoteFileServer) Close() error { if f.container == "" { return nil } - return f.client.ContainerRemove(context.Background(), f.container, types.ContainerRemoveOptions{ + return f.client.ContainerRemove(context.Background(), f.container, containertypes.RemoveOptions{ Force: true, RemoveVolumes: true, })