查詢使用某個image的instances

在Docker中,要查詢所有process很簡單,docker ps就會返回所有執行中的列表,也可以加上-a參數來show所有不管關閉或開啟的機器列表... 而如果希望找到由某個image開起來的instances,可以透過filter + ancestor來做到...

docker ps -f ancestor=[image_name]
範例:
docker ps -f ancestor=registry:2
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
54689a3084a4        registry:2          "/bin/registry /etc/d"   6 weeks ago         Up 13 hours         0.0.0.0:80->5000/tcp     registry
0bcb6beac991        registry:2          "/bin/registry /etc/d"   7 weeks ago         Up 13 hours         0.0.0.0:5000->5000/tcp   mwciotdemo_registry_1
搭配filter也可以透過label的方式來查詢...
幫啟動的instance加上label...
# docker run -d -l mynginx nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
357ea8c3d80b: Pull complete
0fc04568277e: Pull complete
0bed9719ddcb: Pull complete
Digest: sha256:d33834dd25d330da75dccd8add3ae2c9d7b12302b421b02cecb6cb7b34a1b6
Status: Downloaded newer image for nginx:latest
09386387d9f0681935e01ff058023956cd8c61234344f60e8f4c4aedaaad853
透過filter以label的方式來找尋執行中的個體...
# docker ps -f label=mynginx
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
09386387d9f0        nginx               "nginx -g 'daemon off"   17 seconds ago      Up 17 seconds       80/tcp, 443/tcp     determined_swirles
以上,搭配filter來做查詢可以減少很多處理上的麻煩,推薦大家善用filter唷~
Latest