api/types: move ContainerRemoveOptions to api/types/container

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-25 20:25:58 +02:00
parent 9498d897ab
commit 0f77875220
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
31 changed files with 85 additions and 75 deletions

View file

@ -43,13 +43,6 @@ type ContainerLogsOptions struct {
Details bool Details bool
} }
// ContainerRemoveOptions holds parameters to remove containers.
type ContainerRemoveOptions struct {
RemoveVolumes bool
RemoveLinks bool
Force bool
}
// ContainerStartOptions holds parameters to start containers. // ContainerStartOptions holds parameters to start containers.
type ContainerStartOptions struct { type ContainerStartOptions struct {
CheckpointID string CheckpointID string

View file

@ -27,3 +27,10 @@ type CommitOptions struct {
Pause bool Pause bool
Config *Config Config *Config
} }
// RemoveOptions holds parameters to remove containers.
type RemoveOptions struct {
RemoveVolumes bool
RemoveLinks bool
Force bool
}

View file

@ -109,6 +109,11 @@ type ContainerAttachOptions = container.AttachOptions
// Deprecated: use [container.CommitOptions]. // Deprecated: use [container.CommitOptions].
type ContainerCommitOptions = 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 // DecodeSecurityOptions decodes a security options string slice to a type safe
// [system.SecurityOpt]. // [system.SecurityOpt].
// //

View file

@ -4,11 +4,11 @@ import (
"context" "context"
"net/url" "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. // 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{} query := url.Values{}
if options.RemoveVolumes { if options.RemoveVolumes {
query.Set("v", "1") query.Set("v", "1")

View file

@ -9,7 +9,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
@ -19,7 +19,7 @@ func TestContainerRemoveError(t *testing.T) {
client := &Client{ client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 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)) assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
} }
@ -27,7 +27,7 @@ func TestContainerRemoveNotFoundError(t *testing.T) {
client := &Client{ client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "no such container: container_id")), 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.ErrorContains(err, "no such container: container_id"))
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) 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, RemoveVolumes: true,
Force: true, Force: true,
}) })

View file

@ -62,7 +62,7 @@ type ContainerAPIClient interface {
ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerPause(ctx context.Context, container string) 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 ContainerRename(ctx context.Context, container, newContainerName string) error
ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error
ContainerRestart(ctx context.Context, container string, options container.StopOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error

View file

@ -1089,7 +1089,7 @@ func (s *DockerAPISuite) TestContainerAPIDelete(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() 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) assert.NilError(c, err)
} }
@ -1098,7 +1098,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteNotExist(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() 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") assert.ErrorContains(c, err, "No such container: doesnotexist")
} }
@ -1107,7 +1107,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteForce(c *testing.T) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id)) assert.NilError(c, waitRun(id))
removeOptions := types.ContainerRemoveOptions{ removeOptions := container.RemoveOptions{
Force: true, Force: true,
} }
@ -1135,7 +1135,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
links := inspectFieldJSON(c, id2, "HostConfig.Links") links := inspectFieldJSON(c, id2, "HostConfig.Links")
assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers") assert.Equal(c, links, `["/tlink1:/tlink2/tlink1"]`, "expected to have links between containers")
removeOptions := types.ContainerRemoveOptions{ removeOptions := container.RemoveOptions{
RemoveLinks: true, RemoveLinks: true,
} }
@ -1168,7 +1168,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
_, err = os.Stat(source) _, err = os.Stat(source)
assert.NilError(c, err) assert.NilError(c, err)
removeOptions := types.ContainerRemoveOptions{ removeOptions := container.RemoveOptions{
Force: true, Force: true,
RemoveVolumes: true, RemoveVolumes: true,
} }
@ -1549,7 +1549,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteWithEmptyName(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
defer apiClient.Close() 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)) assert.Check(c, errdefs.IsNotFound(err))
} }
@ -2116,7 +2116,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
poll.WaitOn(c, containerExit(ctx, apiclient, ctr.ID), poll.WithDelay(time.Second)) 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, RemoveVolumes: true,
Force: true, Force: true,
}) })

View file

@ -38,7 +38,7 @@ func TestCreateWithCDIDevices(t *testing.T) {
container.WithCmd("/bin/sh", "-c", "env"), container.WithCmd("/bin/sh", "-c", "env"),
container.WithCDIDevices("vendor1.com/device=foo"), 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) inspect, err := apiClient.ContainerInspect(ctx, id)
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -436,7 +436,7 @@ func TestCreateTmpfsOverrideAnonymousVolume(t *testing.T) {
) )
defer func() { defer func() {
err := apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) err := apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true})
assert.NilError(t, err) assert.NilError(t, err)
}() }()

View file

@ -47,7 +47,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
c := d.NewClientT(t) c := d.NewClientT(t)
cID := container.Create(ctx, t, c) 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{}) err := c.ContainerStart(ctx, cID, types.ContainerStartOptions{})
assert.Check(t, err, "error starting test container") assert.Check(t, err, "error starting test container")
@ -105,7 +105,7 @@ func TestDaemonRestartIpcMode(t *testing.T) {
container.WithCmd("top"), container.WithCmd("top"),
container.WithRestartPolicy(containertypes.RestartPolicyAlways), 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) inspect, err := c.ContainerInspect(ctx, cID)
assert.NilError(t, err) 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 // check a new container is created with shareable ipc mode as per new daemon default
cID = container.Run(ctx, t, c) 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) inspect, err = c.ContainerInspect(ctx, cID)
assert.NilError(t, err) assert.NilError(t, err)
@ -156,7 +156,7 @@ func TestDaemonHostGatewayIP(t *testing.T) {
inspect, err := c.NetworkInspect(ctx, "bridge", types.NetworkInspectOptions{}) inspect, err := c.NetworkInspect(ctx, "bridge", types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Contains(res.Stdout(), inspect.IPAM.Config[0].Gateway)) 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) d.Stop(t)
// Verify the IP in /etc/hosts is same as host-gateway-ip // 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.Assert(t, is.Len(res.Stderr(), 0))
assert.Equal(t, 0, res.ExitCode) assert.Equal(t, 0, res.ExitCode)
assert.Check(t, is.Contains(res.Stdout(), "6.7.8.9")) 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) d.Stop(t)
} }

View file

@ -3,7 +3,7 @@ package container
import ( import (
"testing" "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/integration/internal/container"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/daemon" "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. // 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")) id := container.Run(ctx, t, apiClient, container.WithCmd("/bin/sh", "-c", "while true; do echo hello; sleep 1; done"))
defer func() { defer func() {
err := apiClient.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) err := apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true})
assert.NilError(t, err) assert.NilError(t, err)
}() }()

View file

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "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/jsonfilelog"
"github.com/docker/docker/daemon/logger/local" "github.com/docker/docker/daemon/logger/local"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
@ -136,7 +137,7 @@ func testLogs(t *testing.T, logDriver string) {
container.WithTty(tty), container.WithTty(tty),
container.WithLogDriver(logDriver), 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.WaitOn(t, container.IsStopped(ctx, apiClient, id),
poll.WithDelay(time.Millisecond*100), poll.WithDelay(time.Millisecond*100),

View file

@ -192,7 +192,7 @@ func TestMountDaemonRoot(t *testing.T) {
} }
defer func() { 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) panic(err)
} }
}() }()

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "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/filters"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
@ -42,7 +42,7 @@ func TestRemoveContainerWithRemovedVolume(t *testing.T) {
err := os.RemoveAll(tempDir.Path()) err := os.RemoveAll(tempDir.Path())
assert.NilError(t, err) assert.NilError(t, err)
err = apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ err = apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{
RemoveVolumes: true, RemoveVolumes: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)
@ -67,7 +67,7 @@ func TestRemoveContainerWithVolume(t *testing.T) {
assert.Check(t, is.Equal(1, len(insp.Mounts))) assert.Check(t, is.Equal(1, len(insp.Mounts)))
volName := insp.Mounts[0].Name volName := insp.Mounts[0].Name
err = apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ err = apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{
RemoveVolumes: true, RemoveVolumes: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)
@ -85,7 +85,7 @@ func TestRemoveContainerRunning(t *testing.T) {
cID := container.Run(ctx, t, apiClient) 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.ErrorType(err, errdefs.IsConflict))
assert.Check(t, is.ErrorContains(err, "container is running")) assert.Check(t, is.ErrorContains(err, "container is running"))
} }
@ -96,7 +96,7 @@ func TestRemoveContainerForceRemoveRunning(t *testing.T) {
cID := container.Run(ctx, t, apiClient) cID := container.Run(ctx, t, apiClient)
err := apiClient.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ err := apiClient.ContainerRemove(ctx, cID, containertypes.RemoveOptions{
Force: true, Force: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)
@ -106,7 +106,7 @@ func TestRemoveInvalidContainer(t *testing.T) {
ctx := setupTest(t) ctx := setupTest(t)
apiClient := testEnv.APIClient() 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.ErrorType(err, errdefs.IsNotFound))
assert.Check(t, is.ErrorContains(err, "No such container")) assert.Check(t, is.ErrorContains(err, "No such container"))
} }

View file

@ -36,7 +36,7 @@ func TestRenameLinkedContainer(t *testing.T) {
container.Run(ctx, t, apiClient, container.WithName(aName)) 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) assert.NilError(t, err)
bID = container.Run(ctx, t, apiClient, container.WithName(bName), container.WithLinks(aName)) bID = container.Run(ctx, t, apiClient, container.WithName(bName), container.WithLinks(aName))

View file

@ -102,7 +102,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
resp, err := apiClient.ContainerCreate(ctx, tc.config, tc.hostConfig, nil, nil, "") resp, err := apiClient.ContainerCreate(ctx, tc.config, tc.hostConfig, nil, nil, "")
assert.NilError(t, err) 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 { if tc.xStart {
err = apiClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) err = apiClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
@ -192,7 +192,7 @@ func TestContainerWithAutoRemoveCanBeRestarted(t *testing.T) {
testContainer.WithAutoRemove, testContainer.WithAutoRemove,
) )
defer func() { 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 { if t.Failed() && err != nil {
t.Logf("Cleaning up test container failed with error: %v", err) t.Logf("Cleaning up test container failed with error: %v", err)
} }

View file

@ -297,7 +297,7 @@ func TestMacAddressIsAppliedToMainNetworkWithShortID(t *testing.T) {
container.WithStopSignal("SIGKILL"), container.WithStopSignal("SIGKILL"),
container.WithNetworkMode(n[:10]), container.WithNetworkMode(n[:10]),
container.WithMacAddress("02:42:08:26:a9:55")) 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) c := container.Inspect(ctx, t, apiClient, cid)
assert.Equal(t, c.NetworkSettings.Networks["testnet"].MacAddress, "02:42:08:26:a9:55") assert.Equal(t, c.NetworkSettings.Networks["testnet"].MacAddress, "02:42:08:26:a9:55")

View file

@ -210,7 +210,7 @@ func TestWaitRestartedContainer(t *testing.T) {
containerID := container.Run(ctx, t, cli, containerID := container.Run(ctx, t, cli,
container.WithCmd("sh", "-c", "trap 'exit 5' SIGTERM; while true; do sleep 0.1; done"), 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 // Container is running now, wait for exit
waitResC, errC := cli.ContainerWait(ctx, containerID, tc.waitCond) waitResC, errC := cli.ContainerWait(ctx, containerID, tc.waitCond)

View file

@ -410,7 +410,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
Target: "/foo", Target: "/foo",
} }
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"), container.WithRestartPolicy(policy)) 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 // Stop the daemon
d.Restart(t, "--live-restore", "--iptables=false") d.Restart(t, "--live-restore", "--iptables=false")
@ -452,7 +452,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
const testContent = "hello" const testContent = "hello"
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("sh", "-c", "echo "+testContent+">>/foo/test.txt; sleep infinity")) 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. // Wait until container creates a file in the volume.
poll.WaitOn(t, func(t poll.LogT) poll.Result { 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. // Check if a new container with the same volume has access to the previous content.
// This fails if the volume gets unmounted at startup. // This fails if the volume gets unmounted at startup.
cID2 := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("cat", "/foo/test.txt")) 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)) 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 // 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) assert.NilError(t, err)
// Now we should be able to remove the volume // Now we should be able to remove the volume
@ -524,11 +524,11 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
Target: "/foo", Target: "/foo",
} }
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top")) 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") 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) assert.NilError(t, err)
}) })
} }

View file

@ -107,7 +107,7 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
res, err := client.ContainerCommit(ctx, id, containertypes.CommitOptions{Reference: tag}) res, err := client.ContainerCommit(ctx, id, containertypes.CommitOptions{Reference: tag})
assert.NilError(t, err) 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) assert.NilError(t, err)
return res.ID return res.ID

View file

@ -155,7 +155,7 @@ func demultiplexStreams(ctx context.Context, resp types.HijackedResponse) (strea
return s, err 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() t.Helper()
err := apiClient.ContainerRemove(ctx, container, options) err := apiClient.ContainerRemove(ctx, container, options)

View file

@ -4,7 +4,7 @@ import (
"testing" "testing"
"time" "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/container"
"github.com/docker/docker/integration/internal/network" "github.com/docker/docker/integration/internal/network"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
@ -29,7 +29,7 @@ func TestDaemonDNSFallback(t *testing.T) {
defer c.NetworkRemove(ctx, "test") defer c.NetworkRemove(ctx, "test")
cid := container.Run(ctx, t, c, container.WithNetworkMode("test"), container.WithCmd("nslookup", "docker.com")) 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)) poll.WaitOn(t, container.IsSuccessful(ctx, c, cid), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(10*time.Second))
} }

View file

@ -10,6 +10,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
ntypes "github.com/docker/docker/api/types/network" ntypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/network" "github.com/docker/docker/integration/internal/network"
@ -37,14 +38,14 @@ func TestRunContainerWithBridgeNone(t *testing.T) {
c := d.NewClientT(t) c := d.NewClientT(t)
id1 := container.Run(ctx, t, c) 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"}) result, err := container.Exec(ctx, c, id1, []string{"ip", "l"})
assert.NilError(t, err) 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") 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")) 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"}) result, err = container.Exec(ctx, c, id2, []string{"ip", "l"})
assert.NilError(t, err) 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) assert.NilError(t, err, "Failed to get current process network namespace: %+v", err)
id3 := container.Run(ctx, t, c, container.WithNetworkMode("host")) 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}) result, err = container.Exec(ctx, c, id3, []string{"sh", "-c", nsCommand})
assert.NilError(t, err) assert.NilError(t, err)
@ -250,7 +251,7 @@ func TestDefaultNetworkOpts(t *testing.T) {
// Start a container to inspect the MTU of its network interface // Start a container to inspect the MTU of its network interface
id1 := container.Run(ctx, t, c, container.WithNetworkMode(networkName)) 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"}) result, err := container.Exec(ctx, c, id1, []string{"ip", "l", "show", "eth0"})
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -18,6 +18,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
eventtypes "github.com/docker/docker/api/types/events" eventtypes "github.com/docker/docker/api/types/events"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
@ -387,7 +388,7 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
c := d.NewClientT(t) c := d.NewClientT(t)
cID := container.Run(ctx, t, c) 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) _, err = f.Seek(0, io.SeekStart)
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -461,7 +461,7 @@ func testGraphDriver(ctx context.Context, t *testing.T, c client.APIClient, driv
Path: "/hello", Path: "/hello",
}), "diffs: %v", diffs) }), "diffs: %v", diffs)
err = c.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ err = c.ContainerRemove(ctx, id, containertypes.RemoveOptions{
Force: true, Force: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -47,7 +47,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
), ),
) )
cancel() 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 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}) attach, err := client.ContainerAttach(ctx, id, containertypes.AttachOptions{Stream: true, Stdout: true})

View file

@ -60,7 +60,7 @@ func TestReadPluginNoRead(t *testing.T) {
"", "",
) )
assert.Assert(t, err) 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{}) err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
assert.Assert(t, err) assert.Assert(t, err)

View file

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "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/container"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/daemon" "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) { ctrID := container.Create(ctx, t, c, func(ctr *container.TestContainerConfig) {
ctr.HostConfig.Resources.Memory = mem 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{}) err := c.ContainerStart(ctx, ctrID, types.ContainerStartOptions{})
assert.NilError(t, err) assert.NilError(t, err)

View file

@ -8,7 +8,7 @@ import (
"testing" "testing"
"time" "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/filters"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
clientpkg "github.com/docker/docker/client" 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) { 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, Force: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)
@ -135,7 +135,7 @@ func TestVolumesRemoveSwarmEnabled(t *testing.T) {
}) })
t.Run("volume not in use", func(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, Force: true,
}) })
assert.NilError(t, err) assert.NilError(t, err)
@ -321,7 +321,7 @@ VOLUME ` + volDest
img := build.Do(ctx, t, client, fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))) img := build.Do(ctx, t, client, fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile)))
id := container.Create(ctx, t, client, container.WithImage(img)) 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) inspect, err := client.ContainerInspect(ctx, id)
assert.NilError(t, err) assert.NilError(t, err)
@ -331,7 +331,7 @@ VOLUME ` + volDest
volumeName := inspect.Mounts[0].Name volumeName := inspect.Mounts[0].Name
assert.Assert(t, volumeName != "") assert.Assert(t, volumeName != "")
err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}) err = client.ContainerRemove(ctx, id, containertypes.RemoveOptions{})
assert.NilError(t, err) assert.NilError(t, err)
pruneReport, err := client.VolumesPrune(ctx, filters.Args{}) pruneReport, err := client.VolumesPrune(ctx, filters.Args{})

View file

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "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/filters"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client" "github.com/docker/docker/client"
@ -43,9 +44,9 @@ func unpauseAllContainers(ctx context.Context, t testing.TB, client client.Conta
t.Helper() t.Helper()
containers := getPausedContainers(ctx, t, client) containers := getPausedContainers(ctx, t, client)
if len(containers) > 0 { if len(containers) > 0 {
for _, container := range containers { for _, ctr := range containers {
err := client.ContainerUnpause(ctx, container.ID) err := client.ContainerUnpause(ctx, ctr.ID)
assert.Check(t, err, "failed to unpause container %s", container.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 return
} }
for _, container := range containers { for _, ctr := range containers {
if _, ok := protectedContainers[container.ID]; ok { if _, ok := protectedContainers[ctr.ID]; ok {
continue continue
} }
err := apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{ err := apiclient.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{
Force: true, Force: true,
RemoveVolumes: true, RemoveVolumes: true,
}) })
if err == nil || errdefs.IsNotFound(err) || alreadyExists.MatchString(err.Error()) || isErrNotFoundSwarmClassic(err) { if err == nil || errdefs.IsNotFound(err) || alreadyExists.MatchString(err.Error()) || isErrNotFoundSwarmClassic(err) {
continue continue
} }
assert.Check(t, err, "failed to remove %s", container.ID) assert.Check(t, err, "failed to remove %s", ctr.ID)
} }
} }

View file

@ -125,7 +125,7 @@ func (f *remoteFileServer) Close() error {
if f.container == "" { if f.container == "" {
return nil return nil
} }
return f.client.ContainerRemove(context.Background(), f.container, types.ContainerRemoveOptions{ return f.client.ContainerRemove(context.Background(), f.container, containertypes.RemoveOptions{
Force: true, Force: true,
RemoveVolumes: true, RemoveVolumes: true,
}) })