2014-05-09 10:32:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-14 18:02:38 +00:00
|
|
|
"context"
|
2014-05-09 10:32:19 +00:00
|
|
|
"encoding/json"
|
2015-05-22 23:15:14 +00:00
|
|
|
"fmt"
|
2014-11-11 16:17:33 +00:00
|
|
|
"os"
|
2015-01-07 00:04:10 +00:00
|
|
|
"reflect"
|
2015-04-06 13:21:18 +00:00
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2015-02-26 04:16:44 +00:00
|
|
|
|
2017-04-10 12:42:21 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2017-03-23 17:35:22 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
2015-11-18 22:20:54 +00:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2019-08-29 20:52:40 +00:00
|
|
|
"github.com/docker/docker/testutil/fakecontext"
|
2015-12-18 17:58:48 +00:00
|
|
|
"github.com/docker/go-connections/nat"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2014-05-09 10:32:19 +00:00
|
|
|
)
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
type DockerCLICreateSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func (s *DockerCLICreateSuite) TearDownTest(ctx context.Context, c *testing.T) {
|
|
|
|
s.ds.TearDownTest(ctx, c)
|
2022-06-16 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLICreateSuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
2014-05-09 10:32:19 +00:00
|
|
|
// Make sure we can create a simple container with some args
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateArgs(c *testing.T) {
|
2016-10-08 00:50:42 +00:00
|
|
|
// Intentionally clear entrypoint, as the Windows busybox image needs an entrypoint, which breaks this test
|
2023-07-27 22:41:46 +00:00
|
|
|
containerID := cli.DockerCmd(c, "create", "--entrypoint=", "busybox", "command", "arg1", "arg2", "arg with space", "-c", "flags").Stdout()
|
|
|
|
containerID = strings.TrimSpace(containerID)
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out := cli.DockerCmd(c, "inspect", containerID).Combined()
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2018-05-19 11:38:54 +00:00
|
|
|
var containers []struct {
|
2019-08-05 23:54:52 +00:00
|
|
|
Path string
|
|
|
|
Args []string
|
2018-05-19 11:38:54 +00:00
|
|
|
}
|
2015-11-03 04:24:12 +00:00
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "Error inspecting the container: %s", err)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(containers), 1)
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
cont := containers[0]
|
2019-08-05 15:54:15 +00:00
|
|
|
assert.Equal(c, cont.Path, "command", fmt.Sprintf("Unexpected container path. Expected command, received: %s", cont.Path))
|
2014-05-09 10:32:19 +00:00
|
|
|
|
|
|
|
b := false
|
2016-06-07 12:11:11 +00:00
|
|
|
expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"}
|
2014-05-09 10:32:19 +00:00
|
|
|
for i, arg := range expected {
|
2015-04-18 16:46:47 +00:00
|
|
|
if arg != cont.Args[i] {
|
2014-05-09 10:32:19 +00:00
|
|
|
b = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2015-04-18 16:46:47 +00:00
|
|
|
if len(cont.Args) != len(expected) || b {
|
|
|
|
c.Fatalf("Unexpected args. Expected %v, received: %v", expected, cont.Args)
|
2014-05-09 10:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we can set hostconfig options too
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateHostConfig(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
containerID := cli.DockerCmd(c, "create", "-P", "busybox", "echo").Stdout()
|
|
|
|
containerID = strings.TrimSpace(containerID)
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out := cli.DockerCmd(c, "inspect", containerID).Stdout()
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2018-05-19 11:38:54 +00:00
|
|
|
var containers []struct {
|
2014-05-09 10:32:19 +00:00
|
|
|
HostConfig *struct {
|
|
|
|
PublishAllPorts bool
|
|
|
|
}
|
2018-05-19 11:38:54 +00:00
|
|
|
}
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2015-11-03 04:24:12 +00:00
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "Error inspecting the container: %s", err)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(containers), 1)
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2015-11-03 04:24:12 +00:00
|
|
|
cont := containers[0]
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, cont.HostConfig != nil, "Expected HostConfig, got none")
|
|
|
|
assert.Assert(c, cont.HostConfig.PublishAllPorts, "Expected PublishAllPorts, got false")
|
2014-05-09 10:32:19 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateWithPortRange(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
containerID := cli.DockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo").Stdout()
|
|
|
|
containerID = strings.TrimSpace(containerID)
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out := cli.DockerCmd(c, "inspect", containerID).Stdout()
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2018-05-19 11:38:54 +00:00
|
|
|
var containers []struct {
|
2014-11-03 18:15:55 +00:00
|
|
|
HostConfig *struct {
|
|
|
|
PortBindings map[nat.Port][]nat.PortBinding
|
|
|
|
}
|
2018-05-19 11:38:54 +00:00
|
|
|
}
|
2015-11-03 04:24:12 +00:00
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "Error inspecting the container: %s", err)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(containers), 1)
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
cont := containers[0]
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, cont.HostConfig != nil, "Expected HostConfig, got none")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Equal(c, len(cont.HostConfig.PortBindings), 4, fmt.Sprintf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
|
2015-11-03 04:24:12 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
for k, v := range cont.HostConfig.PortBindings {
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Equal(c, len(v), 1, fmt.Sprintf("Expected 1 ports binding, for the port %s but found %s", k, v))
|
|
|
|
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
2014-11-03 18:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateWithLargePortRange(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
containerID := cli.DockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo").Stdout()
|
|
|
|
containerID = strings.TrimSpace(containerID)
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out := cli.DockerCmd(c, "inspect", containerID).Stdout()
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2018-05-19 11:38:54 +00:00
|
|
|
var containers []struct {
|
2014-11-03 18:15:55 +00:00
|
|
|
HostConfig *struct {
|
|
|
|
PortBindings map[nat.Port][]nat.PortBinding
|
|
|
|
}
|
2018-05-19 11:38:54 +00:00
|
|
|
}
|
2015-11-03 04:24:12 +00:00
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(out), &containers)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "Error inspecting the container: %s", err)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(containers), 1)
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
cont := containers[0]
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, cont.HostConfig != nil, "Expected HostConfig, got none")
|
2019-09-09 21:05:57 +00:00
|
|
|
assert.Equal(c, len(cont.HostConfig.PortBindings), 65535)
|
2014-11-03 18:15:55 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
for k, v := range cont.HostConfig.PortBindings {
|
2019-09-09 21:05:57 +00:00
|
|
|
assert.Equal(c, len(v), 1)
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
|
2014-11-03 18:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 10:32:19 +00:00
|
|
|
// "test123" should be printed by docker create + start
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateEchoStdout(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
containerID := cli.DockerCmd(c, "create", "busybox", "echo", "test123").Stdout()
|
|
|
|
containerID = strings.TrimSpace(containerID)
|
2014-05-09 10:32:19 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out := cli.DockerCmd(c, "start", "-ai", containerID).Combined()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, out, "test123\n", "container should've printed 'test123', got %q", out)
|
2014-05-09 10:32:19 +00:00
|
|
|
}
|
2014-11-11 16:17:33 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateVolumesCreated(c *testing.T) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon)
|
2016-10-08 00:50:42 +00:00
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2015-02-20 06:56:02 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test_create_volume"
|
|
|
|
cli.DockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox")
|
2015-07-14 06:35:36 +00:00
|
|
|
|
2016-10-08 00:50:42 +00:00
|
|
|
dir, err := inspectMountSourceField(name, prefix+slash+"foo")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "Error getting volume host path: %q", err)
|
2014-11-11 16:17:33 +00:00
|
|
|
|
|
|
|
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Volume was not created")
|
2014-11-11 16:17:33 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Error statting volume host path: %q", err)
|
2014-11-11 16:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 00:04:10 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateLabels(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test_create_labels"
|
2015-01-07 00:04:10 +00:00
|
|
|
expected := map[string]string{"k1": "v1", "k2": "v2"}
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox")
|
2015-01-07 00:04:10 +00:00
|
|
|
|
|
|
|
actual := make(map[string]string)
|
2017-01-10 18:16:25 +00:00
|
|
|
inspectFieldAndUnmarshall(c, name, "Config.Labels", &actual)
|
2015-01-07 00:04:10 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Expected %s got %s", expected, actual)
|
2015-01-07 00:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateLabelFromImage(c *testing.T) {
|
2015-01-07 00:04:10 +00:00
|
|
|
imageName := "testcreatebuildlabel"
|
2017-03-23 17:35:22 +00:00
|
|
|
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
2017-01-16 10:30:14 +00:00
|
|
|
LABEL k1=v1 k2=v2`))
|
2015-01-07 00:04:10 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test_create_labels_from_image"
|
2015-08-11 23:48:41 +00:00
|
|
|
expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"}
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName)
|
2015-01-07 00:04:10 +00:00
|
|
|
|
|
|
|
actual := make(map[string]string)
|
2017-01-10 18:16:25 +00:00
|
|
|
inspectFieldAndUnmarshall(c, name, "Config.Labels", &actual)
|
2015-01-07 00:04:10 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Expected %s got %s", expected, actual)
|
2015-01-07 00:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-10 21:06:43 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateHostnameWithNumber(c *testing.T) {
|
2024-01-19 11:31:25 +00:00
|
|
|
imgName := "busybox"
|
2016-10-08 00:50:42 +00:00
|
|
|
// Busybox on Windows does not implement hostname command
|
2023-06-14 09:46:00 +00:00
|
|
|
if testEnv.DaemonInfo.OSType == "windows" {
|
2024-01-19 11:31:25 +00:00
|
|
|
imgName = testEnv.PlatformDefaults.BaseImage
|
2016-10-08 00:50:42 +00:00
|
|
|
}
|
2024-01-19 11:31:25 +00:00
|
|
|
out := cli.DockerCmd(c, "run", "-h", "web.0", imgName, "hostname").Combined()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "web.0", "hostname not set, expected `web.0`, got: %s", out)
|
2015-04-10 21:06:43 +00:00
|
|
|
}
|
2015-05-21 14:30:51 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateRM(c *testing.T) {
|
2015-05-21 14:30:51 +00:00
|
|
|
// Test to make sure we can 'rm' a new container that is in
|
|
|
|
// "Created" state, and has ever been run. Test "rm -f" too.
|
|
|
|
|
|
|
|
// create a container
|
2023-07-27 22:41:46 +00:00
|
|
|
cID := cli.DockerCmd(c, "create", "busybox").Stdout()
|
|
|
|
cID = strings.TrimSpace(cID)
|
|
|
|
cli.DockerCmd(c, "rm", cID)
|
2015-05-21 14:30:51 +00:00
|
|
|
|
|
|
|
// Now do it again so we can "rm -f" this time
|
2023-07-27 22:41:46 +00:00
|
|
|
cID = cli.DockerCmd(c, "create", "busybox").Stdout()
|
|
|
|
cID = strings.TrimSpace(cID)
|
|
|
|
cli.DockerCmd(c, "rm", "-f", cID)
|
2015-05-21 14:30:51 +00:00
|
|
|
}
|
2015-05-22 23:15:14 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateModeIpcContainer(c *testing.T) {
|
2016-02-03 00:00:39 +00:00
|
|
|
// Uses Linux specific functionality (--ipc)
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
2015-05-22 23:15:14 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
id := cli.DockerCmd(c, "create", "busybox").Stdout()
|
|
|
|
id = strings.TrimSpace(id)
|
2015-05-22 23:15:14 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox")
|
2015-05-22 23:15:14 +00:00
|
|
|
}
|
2015-07-22 16:14:48 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateByImageID(c *testing.T) {
|
2015-11-18 22:20:54 +00:00
|
|
|
imageName := "testcreatebyimageid"
|
2017-03-23 17:35:22 +00:00
|
|
|
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
2017-01-16 10:30:14 +00:00
|
|
|
MAINTAINER dockerio`))
|
|
|
|
imageID := getIDByName(c, imageName)
|
2015-11-18 22:20:54 +00:00
|
|
|
truncatedImageID := stringid.TruncateID(imageID)
|
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", imageID)
|
|
|
|
cli.DockerCmd(c, "create", truncatedImageID)
|
2015-11-18 22:20:54 +00:00
|
|
|
|
|
|
|
// Ensure this fails
|
|
|
|
out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID))
|
|
|
|
if exit == 0 {
|
|
|
|
c.Fatalf("expected non-zero exit code; received %d", exit)
|
|
|
|
}
|
|
|
|
|
2017-01-11 21:54:52 +00:00
|
|
|
if expected := "invalid reference format"; !strings.Contains(out, expected) {
|
2015-11-18 22:20:54 +00:00
|
|
|
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:00:01 +00:00
|
|
|
if i := strings.IndexRune(imageID, ':'); i >= 0 {
|
|
|
|
imageID = imageID[i+1:]
|
|
|
|
}
|
|
|
|
out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", imageID))
|
2015-11-18 22:20:54 +00:00
|
|
|
if exit == 0 {
|
|
|
|
c.Fatalf("expected non-zero exit code; received %d", exit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if expected := "Unable to find image"; !strings.Contains(out, expected) {
|
|
|
|
c.Fatalf(`Expected %q in output; got: %s`, expected, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateStopSignal(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test_create_stop_signal"
|
|
|
|
cli.DockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox")
|
2015-08-18 17:30:44 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
res := inspectFieldJSON(c, name, "Config.StopSignal")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(res, "9"))
|
2015-08-18 17:30:44 +00:00
|
|
|
}
|
2016-01-08 04:11:21 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateWithWorkdir(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "foo"
|
2016-02-03 14:16:00 +00:00
|
|
|
|
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-03 00:00:39 +00:00
|
|
|
dir := prefix + slash + "home" + slash + "foo" + slash + "bar"
|
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", "--name", name, "-w", dir, "busybox")
|
2016-10-08 00:50:42 +00:00
|
|
|
// Windows does not create the workdir until the container is started
|
2023-06-14 09:46:00 +00:00
|
|
|
if testEnv.DaemonInfo.OSType == "windows" {
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "start", name)
|
2022-02-17 17:25:38 +00:00
|
|
|
if testEnv.DaemonInfo.Isolation.IsHyperV() {
|
2019-09-04 10:55:47 +00:00
|
|
|
// Hyper-V isolated containers do not allow file-operations on a
|
|
|
|
// running container. This test currently uses `docker cp` to verify
|
|
|
|
// that the WORKDIR was automatically created, which cannot be done
|
|
|
|
// while the container is running.
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "stop", name)
|
2019-09-04 10:55:47 +00:00
|
|
|
}
|
2016-10-08 00:50:42 +00:00
|
|
|
}
|
2019-09-04 10:55:47 +00:00
|
|
|
// TODO: rewrite this test to not use `docker cp` for verifying that the WORKDIR was created
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp")
|
2016-01-08 04:11:21 +00:00
|
|
|
}
|
2016-02-27 17:38:26 +00:00
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateWithInvalidLogOpts(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test-invalidate-log-opts"
|
2016-03-02 12:22:18 +00:00
|
|
|
out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "unknown log opt"))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, is.Contains(out, "unknown log opt"))
|
2016-03-02 12:22:18 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
out = cli.DockerCmd(c, "ps", "-a").Stdout()
|
2019-09-09 21:07:46 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, name))
|
2016-02-27 17:38:26 +00:00
|
|
|
}
|
2016-03-07 18:56:24 +00:00
|
|
|
|
|
|
|
// #20972
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreate64ByteHexID(c *testing.T) {
|
2016-03-07 18:56:24 +00:00
|
|
|
out := inspectField(c, "busybox", "Id")
|
2019-08-05 15:54:15 +00:00
|
|
|
imageID := strings.TrimPrefix(strings.TrimSpace(out), "sha256:")
|
2016-03-07 18:56:24 +00:00
|
|
|
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", imageID)
|
2016-03-07 18:56:24 +00:00
|
|
|
}
|
2016-06-18 21:16:05 +00:00
|
|
|
|
|
|
|
// Test case for #23498
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateUnsetEntrypoint(c *testing.T) {
|
2023-07-27 22:41:46 +00:00
|
|
|
const name = "test-entrypoint"
|
2016-06-18 21:16:05 +00:00
|
|
|
dockerfile := `FROM busybox
|
|
|
|
ADD entrypoint.sh /entrypoint.sh
|
|
|
|
RUN chmod 755 /entrypoint.sh
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
CMD echo foobar`
|
|
|
|
|
2017-04-10 12:42:21 +00:00
|
|
|
ctx := fakecontext.New(c, "",
|
|
|
|
fakecontext.WithDockerfile(dockerfile),
|
|
|
|
fakecontext.WithFiles(map[string]string{
|
|
|
|
"entrypoint.sh": `#!/bin/sh
|
2016-06-18 21:16:05 +00:00
|
|
|
echo "I am an entrypoint"
|
|
|
|
exec "$@"`,
|
2017-04-10 12:42:21 +00:00
|
|
|
}))
|
2016-06-18 21:16:05 +00:00
|
|
|
defer ctx.Close()
|
|
|
|
|
2017-04-10 12:42:21 +00:00
|
|
|
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
|
2016-06-18 21:16:05 +00:00
|
|
|
|
2017-04-10 12:42:21 +00:00
|
|
|
out := cli.DockerCmd(c, "create", "--entrypoint=", name, "echo", "foo").Combined()
|
2016-06-18 21:16:05 +00:00
|
|
|
id := strings.TrimSpace(out)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, id != "")
|
2017-04-10 12:42:21 +00:00
|
|
|
out = cli.DockerCmd(c, "start", "-a", id).Combined()
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "foo")
|
2016-06-18 21:16:05 +00:00
|
|
|
}
|
2016-05-26 20:34:48 +00:00
|
|
|
|
|
|
|
// #22471
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLICreateSuite) TestCreateStopTimeout(c *testing.T) {
|
2016-05-26 20:34:48 +00:00
|
|
|
name1 := "test_create_stop_timeout_1"
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox")
|
2016-05-26 20:34:48 +00:00
|
|
|
|
|
|
|
res := inspectFieldJSON(c, name1, "Config.StopTimeout")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(res, "15"))
|
2016-05-26 20:34:48 +00:00
|
|
|
name2 := "test_create_stop_timeout_2"
|
2023-07-27 22:41:46 +00:00
|
|
|
cli.DockerCmd(c, "create", "--name", name2, "busybox")
|
2016-05-26 20:34:48 +00:00
|
|
|
|
|
|
|
res = inspectFieldJSON(c, name2, "Config.StopTimeout")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(res, "null"))
|
2016-05-26 20:34:48 +00:00
|
|
|
}
|