diff --git a/api/client/commands.go b/api/client/commands.go index fefe778498..e03aeb2af4 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -1988,7 +1988,7 @@ func (cid *cidFile) Close() error { if !cid.written { if err := os.Remove(cid.path); err != nil { - return fmt.Errorf("failed to remove CID file '%s': %s \n", cid.path, err) + return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) } } @@ -2096,7 +2096,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { // These are flags not stored in Config/HostConfig var ( flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)") - flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run container in the background and print new container ID") + flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run the container in the background and print the new container ID") flSigProxy = cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxy received signals to the process (even in non-TTY mode). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.") flName = cmd.String([]string{"#name", "-name"}, "", "Assign a name to the container") diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go new file mode 100644 index 0000000000..db59152406 --- /dev/null +++ b/integration-cli/docker_cli_create_test.go @@ -0,0 +1,116 @@ +package main + +import ( + "encoding/json" + "fmt" + "os/exec" + "testing" + "time" +) + +// Make sure we can create a simple container with some args +func TestDockerCreateArgs(t *testing.T) { + runCmd := exec.Command(dockerBinary, "create", "busybox", "command", "arg1", "arg2", "arg with space") + out, _, _, err := runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + cleanedContainerID := stripTrailingCharacters(out) + + inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) + inspectOut, _, err := runCommandWithOutput(inspectCmd) + errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err)) + + containers := []struct { + ID string + Created time.Time + Path string + Args []string + Image string + }{} + if err := json.Unmarshal([]byte(inspectOut), &containers); err != nil { + t.Fatalf("Error inspecting the container: %s", err) + } + if len(containers) != 1 { + t.Fatalf("Unexpected container count. Expected 0, received: %d", len(containers)) + } + + c := containers[0] + if c.Path != "command" { + t.Fatalf("Unexpected container path. Expected command, received: %s", c.Path) + } + + b := false + expected := []string{"arg1", "arg2", "arg with space"} + for i, arg := range expected { + if arg != c.Args[i] { + b = true + break + } + } + if len(c.Args) != len(expected) || b { + t.Fatalf("Unexpected args. Expected %v, received: %v", expected, c.Args) + } + + deleteAllContainers() + + logDone("create - args") +} + +// Make sure we can set hostconfig options too +func TestDockerCreateHostConfig(t *testing.T) { + runCmd := exec.Command(dockerBinary, "create", "-P", "busybox", "echo") + out, _, _, err := runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + cleanedContainerID := stripTrailingCharacters(out) + + inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) + inspectOut, _, err := runCommandWithOutput(inspectCmd) + errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err)) + + containers := []struct { + HostConfig *struct { + PublishAllPorts bool + } + }{} + if err := json.Unmarshal([]byte(inspectOut), &containers); err != nil { + t.Fatalf("Error inspecting the container: %s", err) + } + if len(containers) != 1 { + t.Fatalf("Unexpected container count. Expected 0, received: %d", len(containers)) + } + + c := containers[0] + if c.HostConfig == nil { + t.Fatalf("Expected HostConfig, got none") + } + + if !c.HostConfig.PublishAllPorts { + t.Fatalf("Expected PublishAllPorts, got false") + } + + deleteAllContainers() + + logDone("create - hostconfig") +} + +// "test123" should be printed by docker create + start +func TestDockerCreateEchoStdout(t *testing.T) { + runCmd := exec.Command(dockerBinary, "create", "busybox", "echo", "test123") + out, _, _, err := runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + cleanedContainerID := stripTrailingCharacters(out) + + runCmd = exec.Command(dockerBinary, "start", "-ai", cleanedContainerID) + out, _, _, err = runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + if out != "test123\n" { + t.Errorf("container should've printed 'test123', got '%s'", out) + } + + deleteAllContainers() + + logDone("create - echo test123") +}