A Dockerfile is a text recipe that defines how to build an image: a sequence of instructions that start from a base image and add everything your application needs. It is the reproducible, version-controllable definition of your application's environment — instead of manually configuring a container and hoping to remember the steps, you write them down once and Docker builds the image deterministically every time.
Each instruction — FROM, WORKDIR, COPY, RUN, ENV, EXPOSE, CMD, and others — does a specific job, and most of them add a layer to the image. Writing effective Dockerfiles means choosing the right base image, using the instructions correctly, ordering them well for caching, and keeping images lean and secure. A good Dockerfile is the difference between a bloated, fragile image and a small, reliable one.
This lesson covers the essential Dockerfile instructions and what each does, the important distinction between CMD and ENTRYPOINT, the role of .dockerignore, and the practices that make a Dockerfile produce a clean, efficient, secure image. It is the foundation for building your own images rather than only running others'.