mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #27710 from allencloud/show-num-for-global-service-in-service-ls
support show numbers of global service in service ls command
This commit is contained in:
commit
a70b1d74a0
9 changed files with 74 additions and 62 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
listItemFmt = "%s\t%s\t%s\t%s\n"
|
listItemFmt = "%s\t%s\t%s\t%s\t%s\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
type listOptions struct {
|
type listOptions struct {
|
||||||
|
@ -74,7 +74,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
|
|
||||||
PrintNotQuiet(out, services, nodes, tasks)
|
PrintNotQuiet(out, services, nodes, tasks)
|
||||||
} else if !opts.quiet {
|
} else if !opts.quiet {
|
||||||
// no services and not quiet, print only one line with columns ID, NAME, REPLICAS...
|
// no services and not quiet, print only one line with columns ID, NAME, MODE, REPLICAS...
|
||||||
PrintNotQuiet(out, services, []swarm.Node{}, []swarm.Task{})
|
PrintNotQuiet(out, services, []swarm.Node{}, []swarm.Task{})
|
||||||
} else {
|
} else {
|
||||||
PrintQuiet(out, services)
|
PrintQuiet(out, services)
|
||||||
|
@ -94,34 +94,45 @@ func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node,
|
||||||
}
|
}
|
||||||
|
|
||||||
running := map[string]int{}
|
running := map[string]int{}
|
||||||
|
tasksNoShutdown := map[string]int{}
|
||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if _, nodeActive := activeNodes[task.NodeID]; nodeActive && task.Status.State == "running" {
|
if task.DesiredState != swarm.TaskStateShutdown {
|
||||||
|
tasksNoShutdown[task.ServiceID]++
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, nodeActive := activeNodes[task.NodeID]; nodeActive && task.Status.State == swarm.TaskStateRunning {
|
||||||
running[task.ServiceID]++
|
running[task.ServiceID]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printTable(out, services, running)
|
printTable(out, services, running, tasksNoShutdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTable(out io.Writer, services []swarm.Service, running map[string]int) {
|
func printTable(out io.Writer, services []swarm.Service, running, tasksNoShutdown map[string]int) {
|
||||||
writer := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0)
|
writer := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0)
|
||||||
|
|
||||||
// Ignore flushing errors
|
// Ignore flushing errors
|
||||||
defer writer.Flush()
|
defer writer.Flush()
|
||||||
|
|
||||||
fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "REPLICAS", "IMAGE")
|
fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "MODE", "REPLICAS", "IMAGE")
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
|
mode := ""
|
||||||
replicas := ""
|
replicas := ""
|
||||||
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
|
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
|
||||||
|
mode = "replicated"
|
||||||
replicas = fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas)
|
replicas = fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas)
|
||||||
} else if service.Spec.Mode.Global != nil {
|
} else if service.Spec.Mode.Global != nil {
|
||||||
replicas = "global"
|
mode = "global"
|
||||||
|
replicas = fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID])
|
||||||
}
|
}
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
writer,
|
writer,
|
||||||
listItemFmt,
|
listItemFmt,
|
||||||
stringid.TruncateID(service.ID),
|
stringid.TruncateID(service.ID),
|
||||||
service.Spec.Name,
|
service.Spec.Name,
|
||||||
|
mode,
|
||||||
replicas,
|
replicas,
|
||||||
service.Spec.TaskTemplate.ContainerSpec.Image)
|
service.Spec.TaskTemplate.ContainerSpec.Image)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,14 +45,13 @@ You can verify that the services were correctly created:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
COMMAND
|
29bv0vnlm903 vossibility-stack_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
29bv0vnlm903 vossibility-stack_lookupd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqlookupd
|
4awt47624qwh vossibility-stack_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
4awt47624qwh vossibility-stack_nsqd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqd --data-path=/data --lookupd-tcp-address=lookupd:4160
|
4tjx9biia6fs vossibility-stack_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
||||||
4tjx9biia6fs vossibility-stack_elasticsearch 1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
7563uuzr9eys vossibility-stack_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
||||||
7563uuzr9eys vossibility-stack_kibana 1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
9gc5m4met4he vossibility-stack_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
|
||||||
9gc5m4met4he vossibility-stack_logstash 1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe logstash -f /etc/logstash/conf.d/logstash.conf
|
axqh55ipl40h vossibility-stack_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
|
||||||
axqh55ipl40h vossibility-stack_vossibility-collector 1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba --config /config/config.toml --debug
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related information
|
## Related information
|
||||||
|
|
|
@ -74,9 +74,13 @@ command on a manager node.
|
||||||
$ docker service create --name redis redis:3.0.6
|
$ docker service create --name redis redis:3.0.6
|
||||||
dmu1ept4cxcfe8k8lhtux3ro3
|
dmu1ept4cxcfe8k8lhtux3ro3
|
||||||
|
|
||||||
|
$ docker service create --mode global --name redis2 redis:3.0.6
|
||||||
|
a8q9dasaafudfs8q8w32udass
|
||||||
|
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
dmu1ept4cxcf redis 1/1 redis:3.0.6
|
dmu1ept4cxcf redis replicated 1/1 redis:3.0.6
|
||||||
|
a8q9dasaafud redis2 global 1/1 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a service with 5 replica tasks (--replicas)
|
### Create a service with 5 replica tasks (--replicas)
|
||||||
|
@ -99,8 +103,8 @@ number of `RUNNING` tasks is `3`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
4cdgfyky7ozw redis 3/5 redis:3.0.7
|
4cdgfyky7ozw redis replicated 3/5 redis:3.0.7
|
||||||
```
|
```
|
||||||
|
|
||||||
Once all the tasks are created and `RUNNING`, the actual number of tasks is
|
Once all the tasks are created and `RUNNING`, the actual number of tasks is
|
||||||
|
@ -108,8 +112,8 @@ equal to the desired number:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
4cdgfyky7ozw redis 5/5 redis:3.0.7
|
4cdgfyky7ozw redis replicated 5/5 redis:3.0.7
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a service with a rolling update policy
|
### Create a service with a rolling update policy
|
||||||
|
|
|
@ -46,8 +46,8 @@ For example, given the following service;
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
dmu1ept4cxcf redis 3/3 redis:3.0.6
|
dmu1ept4cxcf redis replicated 3/3 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
Both `docker service inspect redis`, and `docker service inspect dmu1ept4cxcf`
|
Both `docker service inspect redis`, and `docker service inspect dmu1ept4cxcf`
|
||||||
|
|
|
@ -34,15 +34,16 @@ swarm.
|
||||||
|
|
||||||
On a manager node:
|
On a manager node:
|
||||||
```bash
|
```bash
|
||||||
ID NAME REPLICAS IMAGE
|
$ docker service ls
|
||||||
c8wgl7q4ndfd frontend 5/5 nginx:alpine
|
ID NAME MODE REPLICAS IMAGE
|
||||||
dmu1ept4cxcf redis 3/3 redis:3.0.6
|
c8wgl7q4ndfd frontend replicated 5/5 nginx:alpine
|
||||||
|
dmu1ept4cxcf redis replicated 3/3 redis:3.0.6
|
||||||
|
iwe3278osahj mongo global 7/7 mongo:3.3
|
||||||
```
|
```
|
||||||
|
|
||||||
The `REPLICAS` column shows both the *actual* and *desired* number of tasks for
|
The `REPLICAS` column shows both the *actual* and *desired* number of tasks for
|
||||||
the service.
|
the service.
|
||||||
|
|
||||||
|
|
||||||
## Filtering
|
## Filtering
|
||||||
|
|
||||||
The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more
|
The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more
|
||||||
|
@ -60,8 +61,8 @@ The `id` filter matches all or part of a service's id.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls -f "id=0bcjw"
|
$ docker service ls -f "id=0bcjw"
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
0bcjwfh8ychr redis 1/1 redis:3.0.6
|
0bcjwfh8ychr redis replicated 1/1 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Label
|
#### Label
|
||||||
|
@ -74,10 +75,10 @@ its value:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls --filter label=project
|
$ docker service ls --filter label=project
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
01sl1rp6nj5u frontend2 1/1 nginx:alpine
|
01sl1rp6nj5u frontend2 replicated 1/1 nginx:alpine
|
||||||
36xvvwwauej0 frontend 5/5 nginx:alpine
|
36xvvwwauej0 frontend replicated 5/5 nginx:alpine
|
||||||
74nzcxxjv6fq backend 3/3 redis:3.0.6
|
74nzcxxjv6fq backend replicated 3/3 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
The following filter matches only services with the `project` label with the
|
The following filter matches only services with the `project` label with the
|
||||||
|
@ -85,12 +86,11 @@ The following filter matches only services with the `project` label with the
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls --filter label=project=project-a
|
$ docker service ls --filter label=project=project-a
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
36xvvwwauej0 frontend 5/5 nginx:alpine
|
36xvvwwauej0 frontend replicated 5/5 nginx:alpine
|
||||||
74nzcxxjv6fq backend 3/3 redis:3.0.6
|
74nzcxxjv6fq backend replicated 3/3 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Name
|
#### Name
|
||||||
|
|
||||||
The `name` filter matches on all or part of a tasks's name.
|
The `name` filter matches on all or part of a tasks's name.
|
||||||
|
@ -99,8 +99,8 @@ The following filter matches services with a name containing `redis`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls --filter name=redis
|
$ docker service ls --filter name=redis
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
0bcjwfh8ychr redis 1/1 redis:3.0.6
|
0bcjwfh8ychr redis replicated 1/1 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related information
|
## Related information
|
||||||
|
|
|
@ -36,7 +36,7 @@ For example, to remove the redis service:
|
||||||
$ docker service rm redis
|
$ docker service rm redis
|
||||||
redis
|
redis
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME SCALE IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Warning**: Unlike `docker rm`, this command does not ask for confirmation
|
> **Warning**: Unlike `docker rm`, this command does not ask for confirmation
|
||||||
|
|
|
@ -56,8 +56,8 @@ replicas.
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls --filter name=frontend
|
$ docker service ls --filter name=frontend
|
||||||
|
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
3pr5mlvu3fh9 frontend 15/50 nginx:alpine
|
3pr5mlvu3fh9 frontend replicated 15/50 nginx:alpine
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also scale a service using the [`docker service update`](service_update.md)
|
You can also scale a service using the [`docker service update`](service_update.md)
|
||||||
|
@ -80,9 +80,9 @@ backend scaled to 3
|
||||||
frontend scaled to 5
|
frontend scaled to 5
|
||||||
|
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
3pr5mlvu3fh9 frontend 5/5 nginx:alpine
|
3pr5mlvu3fh9 frontend replicated 5/5 nginx:alpine
|
||||||
74nzcxxjv6fq backend 3/3 redis:3.0.6
|
74nzcxxjv6fq backend replicated 3/3 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related information
|
## Related information
|
||||||
|
|
|
@ -47,14 +47,13 @@ You can verify that the services were correctly created:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
COMMAND
|
29bv0vnlm903 vossibility-stack_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
29bv0vnlm903 vossibility-stack_lookupd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqlookupd
|
4awt47624qwh vossibility-stack_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
4awt47624qwh vossibility-stack_nsqd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqd --data-path=/data --lookupd-tcp-address=lookupd:4160
|
4tjx9biia6fs vossibility-stack_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
||||||
4tjx9biia6fs vossibility-stack_elasticsearch 1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
7563uuzr9eys vossibility-stack_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
||||||
7563uuzr9eys vossibility-stack_kibana 1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
9gc5m4met4he vossibility-stack_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
|
||||||
9gc5m4met4he vossibility-stack_logstash 1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe logstash -f /etc/logstash/conf.d/logstash.conf
|
axqh55ipl40h vossibility-stack_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
|
||||||
axqh55ipl40h vossibility-stack_vossibility-collector 1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba --config /config/config.toml --debug
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related information
|
## Related information
|
||||||
|
|
|
@ -65,15 +65,14 @@ Creating service vossibility-stack_vossibility-collector
|
||||||
We can verify that services were correctly created:
|
We can verify that services were correctly created:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# docker service ls
|
$ docker service ls
|
||||||
ID NAME REPLICAS IMAGE
|
ID NAME MODE REPLICAS IMAGE
|
||||||
COMMAND
|
29bv0vnlm903 vossibility-stack_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
29bv0vnlm903 vossibility-stack_lookupd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqlookupd
|
4awt47624qwh vossibility-stack_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
||||||
4awt47624qwh vossibility-stack_nsqd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqd --data-path=/data --lookupd-tcp-address=lookupd:4160
|
4tjx9biia6fs vossibility-stack_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
||||||
4tjx9biia6fs vossibility-stack_elasticsearch 1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
7563uuzr9eys vossibility-stack_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
||||||
7563uuzr9eys vossibility-stack_kibana 1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
9gc5m4met4he vossibility-stack_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
|
||||||
9gc5m4met4he vossibility-stack_logstash 1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe logstash -f /etc/logstash/conf.d/logstash.conf
|
axqh55ipl40h vossibility-stack_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
|
||||||
axqh55ipl40h vossibility-stack_vossibility-collector 1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba --config /config/config.toml --debug
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Managing stacks
|
## Managing stacks
|
||||||
|
|
Loading…
Add table
Reference in a new issue