mirror of https://github.com/docker/docs.git
Merge pull request #1123 from vieux/add_before_support
add support for --before in ps
This commit is contained in:
commit
c2efaadbea
|
@ -152,8 +152,18 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse flags.
|
// Parse flags.
|
||||||
all := boolValue(r, "all")
|
var (
|
||||||
limit := intValueOrZero(r, "limit")
|
all = boolValue(r, "all")
|
||||||
|
limit = intValueOrZero(r, "limit")
|
||||||
|
before *cluster.Container
|
||||||
|
)
|
||||||
|
if value := r.FormValue("before"); value != "" {
|
||||||
|
before = c.cluster.Container(value)
|
||||||
|
if before == nil {
|
||||||
|
httpError(w, fmt.Sprintf("No such container %s", value), http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse filters.
|
// Parse filters.
|
||||||
filters, err := dockerfilters.FromParam(r.Form.Get("filters"))
|
filters, err := dockerfilters.FromParam(r.Form.Get("filters"))
|
||||||
|
@ -184,7 +194,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
candidates := []*cluster.Container{}
|
candidates := []*cluster.Container{}
|
||||||
for _, container := range c.cluster.Containers() {
|
for _, container := range c.cluster.Containers() {
|
||||||
// Skip stopped containers unless -a was specified.
|
// Skip stopped containers unless -a was specified.
|
||||||
if !container.Info.State.Running && !all && limit <= 0 {
|
if !container.Info.State.Running && !all && before == nil && limit <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +242,12 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
// Convert cluster.Container back into dockerclient.Container.
|
// Convert cluster.Container back into dockerclient.Container.
|
||||||
out := []*dockerclient.Container{}
|
out := []*dockerclient.Container{}
|
||||||
for _, container := range candidates {
|
for _, container := range candidates {
|
||||||
|
if before != nil {
|
||||||
|
if container.Id == before.Id {
|
||||||
|
before = nil
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Create a copy of the underlying dockerclient.Container so we can
|
// Create a copy of the underlying dockerclient.Container so we can
|
||||||
// make changes without messing with cluster.Container.
|
// make changes without messing with cluster.Container.
|
||||||
tmp := (*container).Container
|
tmp := (*container).Container
|
||||||
|
|
|
@ -45,6 +45,23 @@ function teardown() {
|
||||||
[[ "${lines[1]}" == *"false"* ]]
|
[[ "${lines[1]}" == *"false"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "docker ps --before" {
|
||||||
|
start_docker_with_busybox 2
|
||||||
|
swarm_manage
|
||||||
|
|
||||||
|
docker_swarm run -d --name c1 busybox echo c1
|
||||||
|
docker_swarm run -d --name c2 busybox echo c2
|
||||||
|
|
||||||
|
run docker_swarm ps --before c1
|
||||||
|
[ "${#lines[@]}" -eq 1 ]
|
||||||
|
|
||||||
|
run docker_swarm ps --before c2
|
||||||
|
[ "${#lines[@]}" -eq 2 ]
|
||||||
|
|
||||||
|
run docker_swarm ps --before c3
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
@test "docker ps --filter" {
|
@test "docker ps --filter" {
|
||||||
start_docker_with_busybox 2
|
start_docker_with_busybox 2
|
||||||
swarm_manage
|
swarm_manage
|
||||||
|
|
Loading…
Reference in New Issue