Docker Tip #52: Referencing Containers and Images by Their Short IDs
Container and image IDs are 64 character SHA-256 IDs. Most Docker commands truncate them to 12 characters, but you only need 4 chars.
When you’re hacking away on the terminal, sometimes it’s more convenient and even faster to reference a Docker container or image by its SHA-256 ID rather than name.
Let’s use the postgres:10.3-alpine image as a working example:
REPOSITORY TAG IMAGE ID postgres 10.3-alpine f4f4231d6f0b
If you wanted to inspect this image, you have 3 options:
docker image inspect postgres:10.3-alpine
docker image inspect f4f4231d6f0b
Chances are you can copy / paste the image ID faster than you can manually type
postgres:10.3-alpine. I did it 5 times and I can copy / paste the ID easily 50% faster.
But it gets better. Here’s a third and even faster way:
docker image inspect f4f4
You only need to reference the first 4 characters of the ID for it to work. Technically you could use the first 3 characters, but you may run into ID collisions.
This method works for both container and image IDs.