docker / for-linux

Docker Engine for Linux
https://docs.docker.com/engine/installation/
756 stars 85 forks source link

docker ps before/since filter unable to find container by name or id #258

Open TylorF opened 6 years ago

TylorF commented 6 years ago

Expected behavior

using a docker ps before/since filter like:

docker ps -a -q -f "before=<container_name/id>"

or

docker ps -a -q -f "since=<container_name/id>"

With set container name, or ID, should return a list of matching containers

Actual behavior

Both name and ID queries return an error:

Error response from daemon: no such container <container_name/id>

Steps to reproduce the behavior

With the following docker ps

user@host ~ $ docker ps
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                    NAMES
f7ef0a16f1af        repo/server:latest        "mysqld"            42 hours ago        Up 4 hours          0.0.0.0:3306->3306/tcp   2018-03-17-mysql
3b368c0fdaf7        repo/orchestrate:latest   "/orchestrate.sh"   4 weeks ago         Up 4 weeks                                   orchestrate

Run a command like

docker ps -a -q -f "before=2018-03-17-mysql"

Receive error:

Error response from daemon: no such container 2018-03-17-mysql

Output of docker version:

Client:
 Version:      17.09.1-ce
 API version:  1.32
 Go version:   go1.8.5
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:19:00 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.09.1-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.5
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:19:00 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

Containers: 2
 Running: 2
 Paused: 0
 Stopped: 0
Images: 72
Server Version: 17.09.1-ce
Storage Driver: overlay
 Backing Filesystem: extfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: v0.13.2 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
 seccomp
  Profile: default
 selinux
Kernel Version: 4.14.19-coreos
Operating System: Container Linux by CoreOS 1632.3.0 (Ladybug)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 31.32GiB
Name: <redacted>
ID: <redacted>
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.)

Physical machine running CoreOS as only operating system (docker version is maintained by them)

Additional Note

A coworker also tried to do the same command on Docker 17.12 on macOS (Docker for mac) and was getting the same error. The command did not work on running nor stopped machines, but previously worked (pre v17 release) in the workflow I'm using.

TylorF commented 6 years ago

This seems to be fixed in version 18.03 for querying by name, but it still seems to fail to query by container id.

vardhmanandroid2015 commented 5 years ago

since & before option does not seem to be working with 18.06.6 CE version as well.... though it is working fine with container name... Do I need to upgrade to newer version or this is not at all supported in CE version

wenjianhn commented 5 years ago

Use the full ID as a workaround.

I'll send a pull request to fix this issue.

mydockergit commented 3 years ago

@wenjianhn it doesn't work even with the full ID:

root@ubuntu:/home/ubuntu/gottybin# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS     NAMES
911dae555915   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             quirky_ritchie
65029dd075c3   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             quirky_dirac
bbf89aab8580   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             nervous_swirles
3fa0a7acdefd   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             pensive_margulis
21dec558f37e   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             blissful_elbakyan
8dd54badf401   ubuntu                 "/bin/bash -c ' echo…"   11 minutes ago   Up 11 minutes             eloquent_dubinsky
root@ubuntu:/home/ubuntu# docker ps --filter "since=bbf89aab8580"
Error response from daemon: no such container bbf89aab8580

I tried to see all the container since "bbf89aab8580" (full ID) and it still failed.

Docker version:

root@ubuntu:/home/ubuntu/gottybin# docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:38 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:50 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
thaJeztah commented 3 years ago

I'm not able to reproduce the problem when using the container name;

docker ps -a
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                  PORTS             NAMES
35efc3511f30   busybox                  "sh -c 'touch /fooba…"   45 minutes ago   Created                                   elastic_leavitt
8e5cb7596fcd   busybox                  "sh"                     6 weeks ago      Created                                   bla
7a9c4f4cd3fd   thajeztah/f3tsh:latest   "/f3tsh"                 7 weeks ago      Exited (2) 2 days ago                     f3tsh.1.udmq009i4j38nkk0n5obuf9zo

docker ps --filter before=bla
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

docker ps --filter since=bla
CONTAINER ID   IMAGE                    COMMAND    CREATED      STATUS      PORTS             NAMES
8db9ffcef1f0   thajeztah/f3tsh:latest   "/f3tsh"   2 days ago   Up 2 days   80/tcp, 443/tcp   f3tsh.1.9rb332ygu7t31zbrp0a431q64

For the id case, that looks indeed that currently only full (non-truncated) ID's are supported;

docker ps --filter since=8e5cb7596fcd
Error response from daemon: no such container 8e5cb7596fcd

docker ps --no-trunc -a
CONTAINER ID                                                       IMAGE                                                                                            COMMAND                                                                           CREATED          STATUS                  PORTS             NAMES
35efc3511f30580355590843ba5e98fe6c78bb9a23a3b26dbc675645960f5dab   busybox                                                                                          "sh -c 'touch /foobar/some-file && umask 002 && touch /foobar/some-other-file'"   47 minutes ago   Created                                   elastic_leavitt
8e5cb7596fcd8d05f716f7a9279fb25641253385789fe5a58253b80d15bb9c0d   busybox                                                                                          "sh"                                                                              6 weeks ago      Created                                   bla
7a9c4f4cd3fd0f9498ab86e5184421948657504eda20413e1310029b9066902d   thajeztah/f3tsh:latest@sha256:60bc56119e80ff42ec4842e9c749dfa6d3cd1c16102a5988f1dfc610265d4e80   "/f3tsh"                                                                          7 weeks ago      Exited (2) 2 days ago                     f3tsh.1.udmq009i4j38nkk0n5obuf9zo

docker ps --filter since=8e5cb7596fcd8d05f716f7a9279fb25641253385789fe5a58253b80d15bb9c0d
CONTAINER ID   IMAGE                    COMMAND    CREATED      STATUS      PORTS             NAMES
8db9ffcef1f0   thajeztah/f3tsh:latest   "/f3tsh"   2 days ago   Up 2 days   80/tcp, 443/tcp   f3tsh.1.9rb332ygu7t31zbrp0a431q64