Closes #13353
Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -52,6 +52,10 @@ func (s *State) String() string {
|
| 52 | 52 |
return "Dead" |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 |
+ if s.StartedAt.IsZero() {
|
|
| 56 |
+ return "Created" |
|
| 57 |
+ } |
|
| 58 |
+ |
|
| 55 | 59 |
if s.FinishedAt.IsZero() {
|
| 56 | 60 |
return "" |
| 57 | 61 |
} |
| ... | ... |
@@ -75,6 +79,10 @@ func (s *State) StateString() string {
|
| 75 | 75 |
return "dead" |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
+ if s.StartedAt.IsZero() {
|
|
| 79 |
+ return "created" |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 78 | 82 |
return "exited" |
| 79 | 83 |
} |
| 80 | 84 |
|
| ... | ... |
@@ -56,6 +56,16 @@ docker-create - Create a new container |
| 56 | 56 |
[**--cgroup-parent**[=*CGROUP-PATH*]] |
| 57 | 57 |
IMAGE [COMMAND] [ARG...] |
| 58 | 58 |
|
| 59 |
+# DESCRIPTION |
|
| 60 |
+ |
|
| 61 |
+Creates a writeable container layer over the specified image and prepares it for |
|
| 62 |
+running the specified command. The container ID is then printed to STDOUT. This |
|
| 63 |
+is similar to **docker run -d** except the container is never started. You can |
|
| 64 |
+then use the **docker start <container_id>** command to start the container at |
|
| 65 |
+any point. |
|
| 66 |
+ |
|
| 67 |
+The initial status of the container created with **docker create** is 'created'. |
|
| 68 |
+ |
|
| 59 | 69 |
# OPTIONS |
| 60 | 70 |
**-a**, **--attach**=[] |
| 61 | 71 |
Attach to STDIN, STDOUT or STDERR. |
| ... | ... |
@@ -37,7 +37,7 @@ the running containers. |
| 37 | 37 |
Provide filter values. Valid filters: |
| 38 | 38 |
exited=<int> - containers with exit code of <int> |
| 39 | 39 |
label=<key> or label=<key>=<value> |
| 40 |
- status=(restarting|running|paused|exited) |
|
| 40 |
+ status=(created|restarting|running|paused|exited) |
|
| 41 | 41 |
name=<string> - container's name |
| 42 | 42 |
id=<ID> - container's ID |
| 43 | 43 |
|
| ... | ... |
@@ -92,7 +92,7 @@ Query Parameters: |
| 92 | 92 |
sizes |
| 93 | 93 |
- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: |
| 94 | 94 |
- `exited=<int>`; -- containers with exit code of `<int>` ; |
| 95 |
- - `status=`(`restarting`|`running`|`paused`|`exited`) |
|
| 95 |
+ - `status=`(`created`|`restarting`|`running`|`paused`|`exited`) |
|
| 96 | 96 |
- `label=key` or `key=value` of a container label |
| 97 | 97 |
|
| 98 | 98 |
Status Codes: |
| ... | ... |
@@ -1033,7 +1033,8 @@ except the container is never started. You can then use the `docker start |
| 1033 | 1033 |
<container_id>` command to start the container at any point. |
| 1034 | 1034 |
|
| 1035 | 1035 |
This is useful when you want to set up a container configuration ahead of time |
| 1036 |
-so that it is ready to start when you need it. |
|
| 1036 |
+so that it is ready to start when you need it. The initial status of the |
|
| 1037 |
+new container is `created`. |
|
| 1037 | 1038 |
|
| 1038 | 1039 |
Please see the [run command](#run) section and the [Docker run reference]( |
| 1039 | 1040 |
/reference/run/) for more details. |
| ... | ... |
@@ -1760,7 +1761,7 @@ The currently supported filters are: |
| 1760 | 1760 |
* label (`label=<key>` or `label=<key>=<value>`) |
| 1761 | 1761 |
* name (container's name) |
| 1762 | 1762 |
* exited (int - the code of exited containers. Only useful with `--all`) |
| 1763 |
-* status (restarting|running|paused|exited) |
|
| 1763 |
+* status (created|restarting|running|paused|exited) |
|
| 1764 | 1764 |
|
| 1765 | 1765 |
##### Successfully exited containers |
| 1766 | 1766 |
|
| ... | ... |
@@ -680,3 +680,54 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
|
| 680 | 680 |
c.Fatalf("docker ps with --size should show virtual size of container")
|
| 681 | 681 |
} |
| 682 | 682 |
} |
| 683 |
+ |
|
| 684 |
+func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|
| 685 |
+ // create a container |
|
| 686 |
+ createCmd := exec.Command(dockerBinary, "create", "busybox") |
|
| 687 |
+ out, _, err := runCommandWithOutput(createCmd) |
|
| 688 |
+ if err != nil {
|
|
| 689 |
+ c.Fatal(out, err) |
|
| 690 |
+ } |
|
| 691 |
+ cID := strings.TrimSpace(out) |
|
| 692 |
+ shortCID := cID[:12] |
|
| 693 |
+ |
|
| 694 |
+ // Make sure it DOESN'T show up w/o a '-a' for normal 'ps' |
|
| 695 |
+ runCmd := exec.Command(dockerBinary, "ps", "-q") |
|
| 696 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 697 |
+ c.Fatal(out, err) |
|
| 698 |
+ } |
|
| 699 |
+ if strings.Contains(out, shortCID) {
|
|
| 700 |
+ c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out)
|
|
| 701 |
+ } |
|
| 702 |
+ |
|
| 703 |
+ // Make sure it DOES show up as 'Created' for 'ps -a' |
|
| 704 |
+ runCmd = exec.Command(dockerBinary, "ps", "-a") |
|
| 705 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 706 |
+ c.Fatal(out, err) |
|
| 707 |
+ } |
|
| 708 |
+ |
|
| 709 |
+ hits := 0 |
|
| 710 |
+ for _, line := range strings.Split(out, "\n") {
|
|
| 711 |
+ if !strings.Contains(line, shortCID) {
|
|
| 712 |
+ continue |
|
| 713 |
+ } |
|
| 714 |
+ hits++ |
|
| 715 |
+ if !strings.Contains(line, "Created") {
|
|
| 716 |
+ c.Fatalf("Missing 'Created' on '%s'", line)
|
|
| 717 |
+ } |
|
| 718 |
+ } |
|
| 719 |
+ |
|
| 720 |
+ if hits != 1 {
|
|
| 721 |
+ c.Fatalf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out)
|
|
| 722 |
+ } |
|
| 723 |
+ |
|
| 724 |
+ // filter containers by 'create' - note, no -a needed |
|
| 725 |
+ runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created") |
|
| 726 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 727 |
+ c.Fatal(out, err) |
|
| 728 |
+ } |
|
| 729 |
+ containerOut := strings.TrimSpace(out) |
|
| 730 |
+ if !strings.HasPrefix(cID, containerOut) {
|
|
| 731 |
+ c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)
|
|
| 732 |
+ } |
|
| 733 |
+} |