An image that runs on your Intel desktop may fail on an Arm laptop. Container images target a platform: an operating system and a CPU architecture. Linux versus Windows matters, and so does Intel/AMD versus Arm. Building an application for one combination does not automatically make it runnable on another. section 12.0
Check the platform before choosing or building an image:
- Use `docker info -f '{{.OSType}}/{{.Architecture}}'` to check the Docker Engine’s OS and native architecture. section 12.1
- Use `docker image inspect IMAGE -f '{{.Os}}/{{.Architecture}}'` to check a local image. Common targets include `linux/amd64`, `linux/arm64`, and `linux/arm`. section 12.1 section 12.2
- If an image has no variant matching the engine’s platform, a pull can fail. A Linux image for a mismatched CPU may instead pull but fail to start with an `exec format error`. section 12.1
Table 12.1 Architectures supported by Docker, with their code names
|
OS
|
CPU
|
Word Length
|
CPU Name
|
CPU Aliases
|
|---|---|---|---|---|
|
Windows
|
Intel/AMD
|
64-bit
|
amd64
|
x86_64, x64
|
|
Linux
|
Intel/AMD
|
64-bit
|
amd64
|
x86_64, x64
|
|
Linux
|
Arm
|
64-bit
|
arm64
|
aarch64, armv8
|
|
Linux
|
Arm
|
32-bit
|
arm
|
arm32v7, armv7, armhf
|
Use the platform table to translate familiar CPU names into Docker’s architecture names, including the distinction between 32-bit and 64-bit Arm. section 12.2
To build for another CPU, select a target with `docker build --platform`, then inspect the resulting image. A multi-stage Dockerfile can serve several platforms when its SDK and runtime base images support them. Otherwise, use platform-specific Dockerfiles and base images; that gives you more control but more files to maintain. Docker Desktop can emulate other CPUs for building and testing Linux variants. section 12.1 section 12.2
# switch to the exercises folder:
cd ch12/exercises
# build for 64-bit Arm:
docker build -t diamol/ch12-hello:2e-linux-arm64 `
--platform linux/arm64 ./hello
# and for 64-bit Intel:
docker build -t diamol/ch12-hello:2e-linux-amd64 `
--platform linux/amd64 ./hello
# check the native architecture of your engine:
docker info -f '{{.OSType}}/{{.Architecture}}'
# and the architecture of the images:
docker image inspect diamol/ch12-hello:2e-linux-arm64 `
-f '{{.Os}}/{{.Architecture}}'
docker image inspect diamol/ch12-hello:2e-linux-amd64 `
-f '{{.Os}}/{{.Architecture}}'
Build the same Go application for `linux/arm64` and `linux/amd64`, then compare each image’s reported platform with the engine’s native platform. section 12.1
Separate architecture-specific tags require users to pick the right one. A multi-platform image instead groups variants under one tag using a manifest list. Docker selects the matching OS-and-CPU variant when the image is used. Run `docker manifest inspect diamol/base:2e` to see which variants a published tag offers without pulling them. section 12.0 section 12.3


