skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search