Sobes.tech
Junior — Middle

Is it possible to build a Docker image without using the FROM directive?

sobes.tech AI

Answer from AI

The FROM directive in a Dockerfile specifies the base image on which a new image is built. Theoretically, it is possible to create a Docker image without using FROM, but then the image will be empty and will not contain an operating system or any tools.

This approach is called "scratch" — a special empty base image. It is used to create minimalist images, for example, to run statically compiled binaries.

Example Dockerfile without FROM:

# Using an empty scratch image
FROM scratch

# Copying a statically compiled binary
COPY myapp /myapp

# Running the application
CMD ["/myapp"]

Thus, it is possible to build an image without a standard base layer, but this is usually used for very specific cases.

Is it possible to build a Docker image without using… - sobes.tech