diff --git a/daemon/list.go b/daemon/list.go index 99242988b0..7389de8047 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -53,7 +53,7 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container, if i, ok := psFilters["status"]; ok { for _, value := range i { - if value == "exited" { + if value == "exited" || value == "created" { all = true } } diff --git a/daemon/state.go b/daemon/state.go index 4119d0e6cd..0270c88e88 100644 --- a/daemon/state.go +++ b/daemon/state.go @@ -52,6 +52,10 @@ func (s *State) String() string { return "Dead" } + if s.StartedAt.IsZero() { + return "Created" + } + if s.FinishedAt.IsZero() { return "" } @@ -75,6 +79,10 @@ func (s *State) StateString() string { return "dead" } + if s.StartedAt.IsZero() { + return "created" + } + return "exited" } diff --git a/docs/man/docker-create.1.md b/docs/man/docker-create.1.md index 546eb3407e..78f3235941 100644 --- a/docs/man/docker-create.1.md +++ b/docs/man/docker-create.1.md @@ -56,6 +56,16 @@ docker-create - Create a new container [**--cgroup-parent**[=*CGROUP-PATH*]] IMAGE [COMMAND] [ARG...] +# DESCRIPTION + +Creates a writeable container layer over the specified image and prepares it for +running the specified command. The container ID is then printed to STDOUT. This +is similar to **docker run -d** except the container is never started. You can +then use the **docker start ** command to start the container at +any point. + +The initial status of the container created with **docker create** is 'created'. + # OPTIONS **-a**, **--attach**=[] Attach to STDIN, STDOUT or STDERR. diff --git a/docs/man/docker-ps.1.md b/docs/man/docker-ps.1.md index 783f4621f6..6c7b18ee34 100644 --- a/docs/man/docker-ps.1.md +++ b/docs/man/docker-ps.1.md @@ -37,7 +37,7 @@ the running containers. Provide filter values. Valid filters: exited= - containers with exit code of label= or label== - status=(restarting|running|paused|exited) + status=(created|restarting|running|paused|exited) name= - container's name id= - container's ID diff --git a/docs/sources/reference/api/docker_remote_api_v1.20.md b/docs/sources/reference/api/docker_remote_api_v1.20.md index c3a42410dd..3433cd17e4 100644 --- a/docs/sources/reference/api/docker_remote_api_v1.20.md +++ b/docs/sources/reference/api/docker_remote_api_v1.20.md @@ -92,7 +92,7 @@ Query Parameters: sizes - **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - `exited=`; -- containers with exit code of `` ; - - `status=`(`restarting`|`running`|`paused`|`exited`) + - `status=`(`created`|`restarting`|`running`|`paused`|`exited`) - `label=key` or `key=value` of a container label Status Codes: diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index 0a6ef38bb0..47afa88d3f 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -1033,7 +1033,8 @@ except the container is never started. You can then use the `docker start ` command to start the container at any point. This is useful when you want to set up a container configuration ahead of time -so that it is ready to start when you need it. +so that it is ready to start when you need it. The initial status of the +new container is `created`. Please see the [run command](#run) section and the [Docker run reference]( /reference/run/) for more details. @@ -1760,7 +1761,7 @@ The currently supported filters are: * label (`label=` or `label==`) * name (container's name) * exited (int - the code of exited containers. Only useful with `--all`) -* status (restarting|running|paused|exited) +* status (created|restarting|running|paused|exited) ##### Successfully exited containers diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index a9d36be491..d93e2118f8 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -680,3 +680,54 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) { c.Fatalf("docker ps with --size should show virtual size of container") } } + +func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) { + // create a container + createCmd := exec.Command(dockerBinary, "create", "busybox") + out, _, err := runCommandWithOutput(createCmd) + if err != nil { + c.Fatal(out, err) + } + cID := strings.TrimSpace(out) + shortCID := cID[:12] + + // Make sure it DOESN'T show up w/o a '-a' for normal 'ps' + runCmd := exec.Command(dockerBinary, "ps", "-q") + if out, _, err = runCommandWithOutput(runCmd); err != nil { + c.Fatal(out, err) + } + if strings.Contains(out, shortCID) { + c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out) + } + + // Make sure it DOES show up as 'Created' for 'ps -a' + runCmd = exec.Command(dockerBinary, "ps", "-a") + if out, _, err = runCommandWithOutput(runCmd); err != nil { + c.Fatal(out, err) + } + + hits := 0 + for _, line := range strings.Split(out, "\n") { + if !strings.Contains(line, shortCID) { + continue + } + hits++ + if !strings.Contains(line, "Created") { + c.Fatalf("Missing 'Created' on '%s'", line) + } + } + + if hits != 1 { + c.Fatalf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out) + } + + // filter containers by 'create' - note, no -a needed + runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created") + if out, _, err = runCommandWithOutput(runCmd); err != nil { + c.Fatal(out, err) + } + containerOut := strings.TrimSpace(out) + if !strings.HasPrefix(cID, containerOut) { + c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out) + } +}