Home > Software design >  get the container ID of an image
get the container ID of an image

Time:12-02

What command do I run to get the container ID of an image?

I would think docker ps -a something...

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS                    PORTS                              NAMES
17ef697da46d   local_django         "/entrypoint /start"     56 minutes ago   Up 56 minutes             0.0.0.0:8000->8000/tcp             django-1

I only want the container ID returned from an image search

CodePudding user response:

You can add the -q option to only get the ID back. And the -f option to filter on 'ancestor' which means the image name or any image in the chain of images it's based on.

ps -aqf ancestor=local_django

CodePudding user response:

Based on image

docker ps -aqf ancestor=<image_name>

You can get it based on name as well

docker ps -aqf name=<container_name>

Also to get all container ids

docker ps -q
  • Related