A Dockerfile is a text file that contains step-by-step instructions to create a Docker Image.


It tells Docker:


Why Dockerfile is Needed

Without Dockerfile With Dockerfile
Manual image creation Automated
Not repeatable Same image every time
Error-prone Version controlled

Common Dockerfile Instructions

FROM

Defines the base image to start from.

FROM openjdk:17

Means: start from a Java 17 environment.


WORKDIR

Sets the working directory inside the container. All following commands run from this path.

WORKDIR /app