4

When I run docker ps,it shows image IDs in the 2nd column: enter image description here But i want it to show image names: enter image description here what should I do ?

AymDev
  • 6,626
  • 4
  • 29
  • 52
  • the name is in the right-most columns. – Miigon Aug 27 '21 at 03:10
  • The names that you are seeing (angry_agnesi, loving_lamport..) are randomly generated names by docker cli. This happens when you don't supply a container name (--name ) in your docker run command or docker-compose.yml file. Also, these look like dangling docker images. Please run `docker system prune` first and then try deploying test containers, after which `docker ps` would give a correct output. – Salvino D'sa Aug 27 '21 at 03:46
  • For starters, after `docker system prune` try running a hello-world container from docker-hub (`docker run hello-world`) and then check the output of `docker ps -a` – Salvino D'sa Aug 27 '21 at 04:00

2 Answers2

2

Use this command to get image name : docker ps -a --format 'table {{.Image}}'

And this command for container name: docker ps -a --format 'table {{.Names}}'

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • This doesn't help in any way as it will still print the image IDs and not their names. – AymDev Dec 01 '22 at 16:15
  • The original question asked is to show image name. Don't confuse container name with image name. – gohm'c Dec 02 '22 at 01:12
  • I don't confuse image and container name. I have the same issue as OP: `docker ps` shows the image ID and not the name, formatting using `{{.Image}}` just prints what's in the *IMAGE* column: for us, the ID. – AymDev Dec 02 '22 at 09:00
0

It's probably because in the meantime the image name and tag was assigned to a different image.

reproduce:

docker pull ubuntu:22.04
docker tag ubuntu:22.04 myimage:mytag
docker run myimage:mytag

here if you do a docker ps -a you will see the container has myimage:mytag in the IMAGE column, however if you now tag a different image with this myimage:mytag:

docker pull debian:buster
docker tag debian:buster myimage:mytag

you will see the IMAGE ID in the IMAGE column of docker ps -a for the previous container because that tag doesn't belong to that image anymore.

zsolt
  • 1,233
  • 8
  • 18