Sobes.tech
Junior — Middle

What is the minimum and maximum number of FROM instructions allowed in a Dockerfile?

sobes.tech AI

Answer from AI

In a Dockerfile, the FROM instruction specifies the base image for the build. The minimum number of FROM instructions is 1, as building without a base image is impossible.

The maximum number of FROM instructions is not strictly limited, but each FROM instruction starts a new build stage (multi-stage build). This allows creating multiple build stages within a single Dockerfile, for example, for compilation and the final image.

An example with two FROM instructions:

FROM golang:1.18 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp

FROM alpine:latest
COPY --from=builder /app/myapp /usr/local/bin/myapp
CMD ["myapp"]

Thus, the minimum number of FROM is 1, and the maximum is practically unlimited, depending on the project needs.