mirror of https://github.com/docker/docs.git
Merge pull request #468 from vieux/ps_n_l
add support for docker ps -l / -n
This commit is contained in:
commit
7945e0a482
10
api/api.go
10
api/api.go
|
@ -10,6 +10,7 @@ import (
|
|||
"net/http"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
@ -117,12 +118,13 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
all := r.Form.Get("all") == "1"
|
||||
limit, _ := strconv.Atoi(r.Form.Get("limit"))
|
||||
|
||||
out := []*dockerclient.Container{}
|
||||
for _, container := range c.cluster.Containers() {
|
||||
tmp := (*container).Container
|
||||
// Skip stopped containers unless -a was specified.
|
||||
if !strings.Contains(tmp.Status, "Up") && !all {
|
||||
if !strings.Contains(tmp.Status, "Up") && !all && limit <= 0 {
|
||||
continue
|
||||
}
|
||||
// Skip swarm containers unless -a was specified.
|
||||
|
@ -151,7 +153,11 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
sort.Sort(sort.Reverse(ContainerSorter(out)))
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(out)
|
||||
if limit > 0 && limit < len(out) {
|
||||
json.NewEncoder(w).Encode(out[:limit])
|
||||
} else {
|
||||
json.NewEncoder(w).Encode(out)
|
||||
}
|
||||
}
|
||||
|
||||
// GET /containers/{name:.*}/json
|
||||
|
|
|
@ -14,3 +14,26 @@ function teardown() {
|
|||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[1]}" == *"Nodes: 3" ]]
|
||||
}
|
||||
|
||||
@test "docker ps -n 3 should return the 3 last containers, including non running one" {
|
||||
skip
|
||||
start_docker 1
|
||||
start_manager
|
||||
run docker_swarm run -d busybox sleep 42
|
||||
run docker_swarm run -d busybox false
|
||||
run docker_swarm run -d busybox true
|
||||
run docker_swarm ps -a -n 3
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
@test "docker ps -l should return the last container, including non running one" {
|
||||
skip
|
||||
start_docker 1
|
||||
start_manager
|
||||
run docker_swarm run -d busybox sleep 42
|
||||
run docker_swarm run -d busybox false
|
||||
run docker_swarm run -d busybox true
|
||||
run docker_swarm ps -l
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
[[ "${lines[1]}" == *"true"* ]]
|
||||
}
|
||||
|
|
|
@ -28,10 +28,12 @@ function swarm() {
|
|||
# Waits until the given docker engine API becomes reachable.
|
||||
function wait_until_reachable() {
|
||||
local attempts=0
|
||||
until docker -H $1 info &> /dev/null || [ $attempts -ge 10 ]; do
|
||||
local max_attempts=5
|
||||
until docker -H $1 info || [ $attempts -ge $max_attempts ]; do
|
||||
echo "Attempt to connect to ${HOSTS[$i]} failed for the $((++attempts)) time" >&2
|
||||
sleep 0.5
|
||||
done
|
||||
[[ $attempts -lt $max_attempts ]]
|
||||
}
|
||||
|
||||
# Start the swarm manager in background.
|
||||
|
|
Loading…
Reference in New Issue