What is a Dockerfile and why does it matter in CI/CD?

Answer

A Dockerfile is a text file containing instructions (FROM, COPY, RUN, CMD, etc.) for building a Docker image — a portable, immutable snapshot of an application and all its dependencies. In CI/CD, the pipeline builds a Docker image from the Dockerfile during the build stage (docker build -t myapp:git-sha .), runs tests inside or against the container, and then pushes the verified image to a container registry (Docker Hub, ECR, GCR). The same image is then deployed to staging and production — guaranteeing that what was tested is exactly what runs in production. This eliminates environment-specific bugs and makes every deployment reproducible. Using a multi-stage Dockerfile keeps production images small by discarding build tools not needed at runtime.