8

When loading an image from a docker hub in dockerFile command FROM, if the platform is not specified, is it loaded based on the current server architecture?

I mean, when I build dockerfile on amazon linux 2 x86, is docker engine get docker image which can running on linux/x86-64? Thank you!!

rabong
  • 139
  • 1
  • 7
  • 1
    If the location where the base image will be loaded from is not specified on your Dockerfile then the image will not be built, is as simple as that. You need to always specify the source from which you wish to build your base image from. – Emmanuel Spencer Egbuniwe Apr 06 '22 at 10:43

1 Answers1

9

The docker build defaults to pulling base images with the platform of the target platform you are building. And that target platform defaults to the platform of your docker host. So if your docker engine is running on linux/amd64, and you do not pass --platform to either docker build or the FROM line, it will attempt to pull linux/amd64 images from a multi platform base image.

You can check your docker host by running:

docker system info --format '{{.OSType}}/{{.Architecture}}'
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Can we check this using any command? – Hemel May 31 '22 at 10:29
  • 1
    @Hemel you can try `docker system info --format '{{.OSType}}/{{.Architecture}}'` – BMitch May 31 '22 at 13:10
  • 1
    Note that `docker system info` does not always give correct results. e.g. on M1 systems `... --format '{{.OSType}}/{{.Architecture}}'` shows: `linux/aarch64`, instead of `linux/arm64` as used by the `--platform` arg. For more, see https://github.com/BretFisher/multi-platform-docker-build – Chadwick Oct 15 '22 at 19:02
  • I don't know if this work for every images, but I had experience with images where passing either `--platform linux/arm64` or `--platform linux/aarch64` was resolved to the same image. (Docker 20.10.22) – bric3 Feb 16 '23 at 14:06