What is dockerfile?

A Dockerfile is a plain‑text file that contains a list of commands telling Docker how to build a custom image. Think of it as a recipe: each line is an instruction (like “add this file”, “install this program”, “set this environment variable”) that Docker follows to create a ready‑to‑run container image.

Let's break it down

  • FROM - starts the recipe by picking a base image (e.g., Ubuntu, Node, Python).
  • RUN - runs a command inside the image while it’s being built (usually to install packages).
  • COPY / ADD - puts files from your computer into the image.
  • WORKDIR - sets the default folder where later commands will run.
  • ENV - defines environment variables that the container can use.
  • EXPOSE - tells Docker which network ports the container will listen on.
  • CMD / ENTRYPOINT - defines the command that runs when you start a container from the image.

Why does it matter?

Dockerfiles let you create the exact same environment every time, on any machine. This eliminates “it works on my computer” problems, speeds up setup for new developers, and makes it easy to ship software with all its dependencies already baked in.

Where is it used?

  • Building micro‑services that run in containers.
  • Setting up development environments for teams.
  • Creating CI/CD pipelines that automatically build and test code.
  • Packaging applications for cloud platforms like AWS ECS, Google Cloud Run, or Azure Container Instances.

Good things about it

  • Reproducible: identical images every build.
  • Versionable: stored in source control like any code file.
  • Portable: works on any host with Docker installed.
  • Layered caching: Docker reuses unchanged steps, making builds faster.
  • Transparent: you can read the file to see exactly what’s inside the image.

Not-so-good things

  • Learning curve: beginners may find the syntax and concepts confusing at first.
  • Large images: if you add unnecessary layers or files, images can become bulky.
  • Security risks: copying secrets or using outdated base images can expose vulnerabilities.
  • Cache pitfalls: changes in early steps can force a full rebuild, slowing down CI pipelines.
  • Limited logic: Dockerfile isn’t a full programming language, so complex build logic can become messy.