Skip to main content

What is a Dockerfile?

A Dockerfile is a text file with a set of instructions that describe how to build a Docker image. Each line in a Dockerfile is a build step (installing dependencies, copying files, running commands, etc.).


What a Dockerfile does

  • sets the base image (for example, ubuntu or python:3.10);
  • copies project files into the future image;
  • installs dependencies;
  • configures the working directory and environment variables;
  • specifies the command that will run when the container starts.

The simplest example of a Dockerfile

Dockerfile
FROM python:3.10 WORKDIR /app COPY . . RUN pip install -r requirements.txt CMD ["python", "app.py"]

How it is used

  1. Write the Dockerfile
  2. Build the image:
bash
docker build -t myapp .
  1. Run the container:
bash
docker run myapp

In short: a Dockerfile is the recipe. A Docker image is the finished dish. A container is a running instance of that "dish" in action.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.