How to filter docker process based on image

Priya Dharshini picture Priya Dharshini · Apr 2, 2015 · Viewed 24.5k times · Source

I have been trying to get the container id of docker instance using docker process command, but when i'm trying with filter by name it works fine for me.

sudo -S docker ps -q --filter="name=romantic_rosalind"

Results container id :

3c7e865f1dfb

But when i filter using image i'm getting all the instance container ids :

sudo -S docker ps -q  --filter="image=docker-mariadb:1.0.1"

Results Container ids :

5570dc09b581

3c7e865f1dfb

But i wish to get only container id of mariadb.

How to get container id of docker process using filter as image ?

Answer

Ruben Sancho Ramos picture Ruben Sancho Ramos · Nov 6, 2015

Use "ancestor" instead of "image" that works great. Example:

sudo -S docker ps -q  --filter ancestor=docker-mariadb:1.0.1

The Docker team may have added it in the last versions: http://docs.docker.com/engine/reference/commandline/ps/