Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker ps - show image ID instead of name

I display running containers using docker ps command. There is an IMAGE column that shows name of the image that each container was created from. However in the meantime (while containers were running) I have rebuilt some images. The new images have the same names but different IDs. Now I'd like to check from which image specific container was run. I cannot deduce this information using only image name. I need image ID. Is there any possibility to display ID of the image that was used to run specific container?

like image 970
k13i Avatar asked Jan 07 '19 13:01

k13i


People also ask

Is container ID and image ID same?

Like IMAGE ID, CONTAINER ID is the true identifier for the container. It has the same form, but it identifies a different kind of object. docker ps only outputs running containers. You can view all containers (running or stopped) with docker ps -a.


1 Answers

You can pass multiple container-ids to the docker inspect command and then use the --format to only get the values that you want.

docker inspect --format='{{.Id}} {{.Name}} {{.Image}}' $(docker ps -aq)

This will give you a list of the docker container Ids, names and image IDs that are being used for all of your containers.

asdf1234 /mydockercontainer sha256:abcd1234

https://docs.docker.com/engine/reference/commandline/inspect/

like image 75
sktan Avatar answered Oct 07 '22 12:10

sktan