mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
client/container_create: Rename ContainerName to Name
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -34,8 +34,8 @@ func (cli *Client) ContainerCreate(ctx context.Context, options ContainerCreateO
|
||||
}
|
||||
}
|
||||
|
||||
if options.ContainerName != "" {
|
||||
query.Set("name", options.ContainerName)
|
||||
if options.Name != "" {
|
||||
query.Set("name", options.Name)
|
||||
}
|
||||
|
||||
body := container.CreateRequest{
|
||||
|
||||
@@ -12,7 +12,7 @@ type ContainerCreateOptions struct {
|
||||
HostConfig *container.HostConfig
|
||||
NetworkingConfig *network.NetworkingConfig
|
||||
Platform *ocispec.Platform
|
||||
ContainerName string
|
||||
Name string
|
||||
}
|
||||
|
||||
// ContainerCreateResult is the result from creating a container.
|
||||
|
||||
@@ -22,11 +22,11 @@ func TestContainerCreateError(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: nil, ContainerName: "nothing"})
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: nil, Name: "nothing"})
|
||||
assert.Error(t, err, "config is nil")
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, ContainerName: "nothing"})
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, Name: "nothing"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
|
||||
// 404 doesn't automatically means an unknown image
|
||||
@@ -35,7 +35,7 @@ func TestContainerCreateError(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, ContainerName: "nothing"})
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, Name: "nothing"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestContainerCreateImageNotFound(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{Image: "unknown_image"}, ContainerName: "unknown"})
|
||||
_, err = client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{Image: "unknown_image"}, Name: "unknown"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestContainerCreateWithName(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
r, err := client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, ContainerName: "container_name"})
|
||||
r, err := client.ContainerCreate(context.Background(), ContainerCreateOptions{Config: &container.Config{}, Name: "container_name"})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(r.ID, "container_id"))
|
||||
}
|
||||
|
||||
@@ -770,7 +770,7 @@ func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
|
||||
Config: &config,
|
||||
HostConfig: &container.HostConfig{},
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name,
|
||||
Name: name,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
@@ -1018,7 +1018,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig1,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name,
|
||||
Name: name,
|
||||
})
|
||||
expected := "Invalid value 1-42,, for cpuset cpus"
|
||||
assert.ErrorContains(c, err, expected)
|
||||
@@ -1033,7 +1033,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithWrongCpusetValues(c *testin
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig2,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name2,
|
||||
Name: name2,
|
||||
})
|
||||
expected = "Invalid value 42-3,1-- for cpuset mems"
|
||||
assert.ErrorContains(c, err, expected)
|
||||
@@ -1085,7 +1085,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name,
|
||||
Name: name,
|
||||
})
|
||||
|
||||
expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]"
|
||||
@@ -1100,7 +1100,7 @@ func (s *DockerAPISuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name2,
|
||||
Name: name2,
|
||||
})
|
||||
|
||||
expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]"
|
||||
@@ -1138,7 +1138,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
|
||||
Config: &config,
|
||||
HostConfig: &container.HostConfig{},
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name,
|
||||
Name: name,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
@@ -1516,7 +1516,7 @@ func (s *DockerAPISuite) TestContainerAPICreateMountsBindRead(c *testing.T) {
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: "test",
|
||||
Name: "test",
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
@@ -1772,7 +1772,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsTmpfs(c *testing.T) {
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: cName,
|
||||
Name: cName,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
out := cli.DockerCmd(c, "start", "-a", cName).Combined()
|
||||
|
||||
@@ -65,10 +65,10 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T
|
||||
Target: containerPipeName,
|
||||
},
|
||||
},
|
||||
},
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: name,
|
||||
})
|
||||
},
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
Name: name,
|
||||
})
|
||||
assert.NilError(c, err)
|
||||
|
||||
err = apiClient.ContainerStart(ctx, name, client.ContainerStartOptions{})
|
||||
|
||||
@@ -600,7 +600,7 @@ func (s *DockerCLIVolumeSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c
|
||||
Config: &config,
|
||||
HostConfig: &hostConfig,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: "app",
|
||||
Name: "app",
|
||||
})
|
||||
|
||||
assert.NilError(c, err)
|
||||
|
||||
@@ -291,7 +291,7 @@ func TestCreateWithCustomMaskedPaths(t *testing.T) {
|
||||
Privileged: tc.privileged,
|
||||
MaskedPaths: tc.maskedPaths,
|
||||
},
|
||||
ContainerName: fmt.Sprintf("create-masked-paths-%d", i),
|
||||
Name: fmt.Sprintf("create-masked-paths-%d", i),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -362,7 +362,7 @@ func TestCreateWithCustomReadonlyPaths(t *testing.T) {
|
||||
Privileged: tc.privileged,
|
||||
ReadonlyPaths: tc.readonlyPaths,
|
||||
},
|
||||
ContainerName: fmt.Sprintf("create-readonly-paths-%d", i),
|
||||
Name: fmt.Sprintf("create-readonly-paths-%d", i),
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ func TestContainerVolumeAnonymous(t *testing.T) {
|
||||
HostConfig: config.HostConfig,
|
||||
NetworkingConfig: config.NetworkingConfig,
|
||||
Platform: config.Platform,
|
||||
ContainerName: config.Name,
|
||||
Name: config.Name,
|
||||
})
|
||||
// We use [testNonExistingPlugin] for this, which produces an error
|
||||
// when used, which we use as indicator that the driver was passed
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestGraphDriverPersistence(t *testing.T) {
|
||||
Image: testImage,
|
||||
Cmd: []string{"echo", "test"},
|
||||
},
|
||||
ContainerName: "test-container",
|
||||
Name: "test-container",
|
||||
})
|
||||
assert.NilError(t, err, "Failed to create container")
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func Create(ctx context.Context, t *testing.T, apiClient client.APIClient, ops .
|
||||
HostConfig: config.HostConfig,
|
||||
NetworkingConfig: config.NetworkingConfig,
|
||||
Platform: config.Platform,
|
||||
ContainerName: config.Name,
|
||||
Name: config.Name,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -79,7 +79,7 @@ func CreateFromConfig(ctx context.Context, apiClient client.APIClient, config *T
|
||||
HostConfig: config.HostConfig,
|
||||
NetworkingConfig: config.NetworkingConfig,
|
||||
Platform: config.Platform,
|
||||
ContainerName: config.Name,
|
||||
Name: config.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -968,7 +968,7 @@ func TestEmptyPortBindingsBC(t *testing.T) {
|
||||
HostConfig: config.HostConfig,
|
||||
NetworkingConfig: config.NetworkingConfig,
|
||||
Platform: config.Platform,
|
||||
ContainerName: config.Name,
|
||||
Name: config.Name,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
defer apiClient.ContainerRemove(ctx, c.ID, client.ContainerRemoveOptions{Force: true})
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestRunMountVolumeSubdir(t *testing.T) {
|
||||
Config: &cfg,
|
||||
HostConfig: &hostCfg,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: ctrName,
|
||||
Name: ctrName,
|
||||
})
|
||||
id := create.ID
|
||||
if id != "" {
|
||||
@@ -184,7 +184,7 @@ func TestRunMountImage(t *testing.T) {
|
||||
Config: &cfg,
|
||||
HostConfig: &hostCfg,
|
||||
NetworkingConfig: &network.NetworkingConfig{},
|
||||
ContainerName: ctrName,
|
||||
Name: ctrName,
|
||||
})
|
||||
id := create.ID
|
||||
if id != "" {
|
||||
|
||||
@@ -155,9 +155,9 @@ COPY . /static`); err != nil {
|
||||
|
||||
// Start the container
|
||||
b, err := c.ContainerCreate(context.Background(), client.ContainerCreateOptions{
|
||||
Config: &containertypes.Config{Image: imgName},
|
||||
HostConfig: &containertypes.HostConfig{PublishAllPorts: true},
|
||||
ContainerName: ctrName,
|
||||
Config: &containertypes.Config{Image: imgName},
|
||||
HostConfig: &containertypes.HostConfig{PublishAllPorts: true},
|
||||
Name: ctrName,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
err = c.ContainerStart(context.Background(), b.ID, client.ContainerStartOptions{})
|
||||
|
||||
4
vendor/github.com/moby/moby/client/container_create.go
generated
vendored
4
vendor/github.com/moby/moby/client/container_create.go
generated
vendored
@@ -34,8 +34,8 @@ func (cli *Client) ContainerCreate(ctx context.Context, options ContainerCreateO
|
||||
}
|
||||
}
|
||||
|
||||
if options.ContainerName != "" {
|
||||
query.Set("name", options.ContainerName)
|
||||
if options.Name != "" {
|
||||
query.Set("name", options.Name)
|
||||
}
|
||||
|
||||
body := container.CreateRequest{
|
||||
|
||||
2
vendor/github.com/moby/moby/client/container_create_opts.go
generated
vendored
2
vendor/github.com/moby/moby/client/container_create_opts.go
generated
vendored
@@ -12,7 +12,7 @@ type ContainerCreateOptions struct {
|
||||
HostConfig *container.HostConfig
|
||||
NetworkingConfig *network.NetworkingConfig
|
||||
Platform *ocispec.Platform
|
||||
ContainerName string
|
||||
Name string
|
||||
}
|
||||
|
||||
// ContainerCreateResult is the result from creating a container.
|
||||
|
||||
Reference in New Issue
Block a user