Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter docker process based on image

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 ?

like image 322
Priya Dharshini Avatar asked Apr 02 '15 06:04

Priya Dharshini


People also ask

What docker is my image running?

You can check with this command systemctl status docker it will show the status of the docker. If you want to start you can use systemctl start docker instead of systemctl you can try also with service , service docker status and service docker start respectively.

How do I analyze a docker image?

To analyze a Docker image, simply run dive command with Docker "Image ID". You can get your Docker images' IDs using "sudo docker images" command. Here, ea4c82dcd15a is Docker image id. The Dive command will quickly analyze the given Docker image and display its contents in the Terminal.

What is a docker image digest?

Pulling an image using name@sha256:digest A digest is an id that is automatically created during build time and cannot be changed (immutable).


3 Answers

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/

like image 150
Ruben Sancho Ramos Avatar answered Oct 22 '22 08:10

Ruben Sancho Ramos


You can use awk and grep to filter specified container id. For example:

docker ps | grep "docker-mariadb:1.0.1" | awk '{ print $1 }'

This will print id of your container.

like image 36
wsl Avatar answered Oct 22 '22 09:10

wsl


docker ps -a | awk '{ print $1,$2 }' | grep imagename | awk '{print $1 }'

This is perfect. if you need you can add a filter of running images of a particular stsatus alone, like below

docker ps -a --filter=running | awk '{ print $1,$2 }' | grep rulsoftreg:5000/mypayroll/cisprocessing-printdocsnotifyconsumer:latest | awk '{print $1 }'

Various other filter options can be explored here

https://docs.docker.com/v1.11/engine/reference/commandline/ps/

like image 4
Mohammed Rafeeq Avatar answered Oct 22 '22 09:10

Mohammed Rafeeq