The FROM instruction in a Dockerfile initializes a new build stage and sets the base image for subsequent instructions, serving as the foundation upon which your custom image is built.
The FROM instruction is the most essential command in a Dockerfile, as it defines the starting point for your image. It specifies an existing image that Docker should use as the base layer, on top of which all subsequent instructions like COPY, RUN, and ADD will be applied. Every valid Dockerfile must begin with a FROM instruction, except when using advanced features like multi-stage builds where multiple FROM statements can appear . This base image provides the operating system, runtime environment, and any pre-installed software that your application depends on.
The basic syntax is FROM [--platform=<platform>] <image>[:<tag> | @<digest>]. The image parameter specifies the image name, which Docker will look for locally first, then attempt to pull from a registry like Docker Hub if not found locally. The optional tag (defaulting to latest) pins a specific version, while the digest provides an even more precise reference using the image's cryptographic hash . The platform flag allows you to target specific architectures like linux/amd64 or linux/arm64 when building multi-architecture images .
The image specified by FROM must exist locally or be accessible from a configured registry; Docker will automatically pull it if missing .
Only the last FROM in a single-stage build determines the final image; in multi-stage builds, you can copy artifacts between stages .
The base image provides the root filesystem for your container, including the OS, runtime, libraries, and system tools .
Security and image size considerations should guide your base image choice—Alpine Linux (5MB) offers smaller attack surface than full Ubuntu (70MB) .
Official images from Docker Hub (like python:3.12) are curated and maintained, providing a reliable foundation .