Get Architecture of Docker Images

Get Architecture of Docker Images

In heterogeneous environments that span multiple CPU architectures (e.g. x86_64, ARM), identifying the architecture of Docker images is an essential step for ensuring reliable builds and deployments. This is especially true when building containers for deployment on different hardware, such as Raspberry Pis, cloud platforms, or cross-platform CI/CD pipelines. This tutorial explains how to get architecture of Docker images.

Docker doesn't directly show image architectures in the standard docker image ls output, but you can easily extract this information using a simple one-line command.

docker image inspect --format "{{.ID}} {{.RepoTags}} {{.Architecture}}" $(docker image ls -q)

The command works by first using the docker image ls -q to list all Docker image IDs in quiet mode, which outputs only the IDs without additional formatting. These IDs are then passed to docker image inspect, which retrieves detailed metadata for each image. To extract specific fields, the --format option is used that prints the image ID, associated tags (e.g., ubuntu:latest), and the CPU architecture (e.g. amd64).

Output example:

sha256:602eb6fb314b5fafad376a32ab55194e535e533dec6552f82b70d7ac0e554b1c [ubuntu:latest] amd64
sha256:368eb09313237cb0296ef50d45fa314f379a4ba82389d2444e578df11b7241e3 [debian:latest] arm64

Leave a Comment

Cancel reply

Your email address will not be published.