docker / cli

The Docker CLI
Apache License 2.0
4.97k stars 1.95k forks source link

docker stack ps and docker ps names inconsistent after docker stack rm #926

Open remingtonc opened 6 years ago

remingtonc commented 6 years ago

Description

docker stack ps <stackname> immediately loses the name references after issuing docker stack rm <stackname>. docker ps output still has the names. This inconsistency breaks docker wait $(docker stack ps --no-trunc --format "{{.Name}}.{{.ID}}" <stackname>) functionality.

Migrating issue from https://github.com/docker/for-mac/issues/2672

Steps to reproduce the issue:

  1. Create docker stack.
  2. Run docker stack rm <stackname> && docker ps && docker stack ps <stackname> and inspect output.

Describe the results you received:

bash-3.2$ docker stack rm tdm && docker ps && docker stack ps tdm
Removing service tdm_dbms
Removing service tdm_etl
Removing network tdm_backend
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS               NAMES
8462a8d91706        tdm_etl:latest            "pipenv run python m…"   11 seconds ago      Up 7 seconds                            tdm_etl.up0g4yhadxlkc6kbrjf41mxy1.65t2lufgp76rmbzakh3kqtxjn
0875ee5278ba        arangodb/arangodb:3.3.3   "/entrypoint.sh aran…"   14 seconds ago      Up 9 seconds        8529/tcp            tdm_dbms.1.15temwzu948jscb0lc8wkc8kc
ID                  NAME                                                  IMAGE                     NODE                    DESIRED STATE       CURRENT STATE            ERROR               PORTS
65t2lufgp76r        mqccmjlx49ffe16ze20srmcvf.up0g4yhadxlkc6kbrjf41mxy1   tdm_etl:latest            linuxkit-025000000001   Remove              Running 9 seconds ago
15temwzu948j        lowa408eli2eiqwk2x35870ud.1                           arangodb/arangodb:3.3.3   linuxkit-025000000001   Remove              Running 11 seconds ago
# Pulled from an earlier command, just demonstrating output
bash-3.2$ docker wait $(docker stack ps --no-trunc --format "{{.Name}}.{{.ID}}" tdm)
Error response from daemon: No such container: 2nd4uhp3ey78mxhl3vm706687.up0g4yhadxlkc6kbrjf41mxy1.mcn9f69ft9pw52613h8g2x749
Error response from daemon: No such container: zgixm0rf01mx9fkveg0qdfxwv.1.akzc8h2dz30edtyfhkvya3vm9

Describe the results you expected:

bash-3.2$ docker stack rm tdm && docker ps && docker stack ps tdm
Removing service tdm_dbms
Removing service tdm_etl
Removing network tdm_backend
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS               NAMES
8462a8d91706        tdm_etl:latest            "pipenv run python m…"   11 seconds ago      Up 7 seconds                            tdm_etl.up0g4yhadxlkc6kbrjf41mxy1.65t2lufgp76rmbzakh3kqtxjn
0875ee5278ba        arangodb/arangodb:3.3.3   "/entrypoint.sh aran…"   14 seconds ago      Up 9 seconds        8529/tcp            tdm_dbms.1.15temwzu948jscb0lc8wkc8kc
ID                  NAME                                                  IMAGE                     NODE                    DESIRED STATE       CURRENT STATE            ERROR               PORTS
65t2lufgp76r        tdm_etl.up0g4yhadxlkc6kbrjf41mxy1.65t2lufgp76rmbzakh3kqtxjn   tdm_etl:latest            linuxkit-025000000001   Remove              Running 9 seconds ago
15temwzu948j        tdm_dbms.1.15temwzu948jscb0lc8wkc8kc                           arangodb/arangodb:3.3.3   linuxkit-025000000001   Remove              Running 11 seconds ago
bash-3.2$ docker wait $(docker stack ps --no-trunc --format "{{.Name}}.{{.ID}}" tdm)
...

Additional information you deem important (e.g. issue happens only occasionally): Haven't completely validated the docker wait methodology exposed above - looks like sometimes docker stack ps outputs the full name sometimes and a truncated name other times.

Output of docker version:

bash-3.2$ docker version
Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:03:51 2017
 OS/Arch:   darwin/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:12:29 2017
  OS/Arch:  linux/amd64
  Experimental: true

Output of docker info:

bash-3.2$ docker info
Containers: 31
 Running: 0
 Paused: 0
 Stopped: 31
Images: 205
Server Version: 17.12.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: up0g4yhadxlkc6kbrjf41mxy1
 Is Manager: true
 ClusterID: cx8l2pivd9rcpuwt55al326wy
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 192.168.65.3
 Manager Addresses:
  192.168.65.3:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: B4QV:JIRY:Y224:6B4S:QQET:NPOJ:CUOK:DUR3:TIXO:CXJU:YQBC:Z4TB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 36
 Goroutines: 150
 System Time: 2018-03-07T19:08:41.697781Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.): Physical, Docker for Mac.

dnephin commented 6 years ago

I believe stack rm will remove the services/tasks before returning, but that doesn't guarantee the containers associated with those tasks have finished their shutdown. The container shutdown will be async.

remingtonc commented 6 years ago

@dnephin In this case I need to wait for certain containers in the stack to finish executing before proceeding with other operations. I can accomplish this through workarounds, but it feels hacky and it makes more sense for there to be some level of operational consistency when trying to work against certain containers in stacks - especially if what needs to be accomplished is only possible through base level docker commands and doesn’t have equivalent docker stack functionality. Current behavior is divergent and somewhat incompatible.