Skip to main content

What does "build context" mean?

Build context is the folder (directory) whose contents Docker passes into the image build process. In simple terms, everything inside that folder can be used by Docker inside the Dockerfile (for example, in a COPY or ADD instruction).

What it looks like

If you run the command:

bash
docker build -t myimage .

The dot . is the build context, meaning the current folder. Docker sends its contents to the daemon, and from there pulls files for the build.

Why build context is needed

  • so Docker knows which files can be copied into the image (COPY . /app)
  • so it doesn't give access to the entire filesystem
  • so the build stays reproducible and bounded

An important rule (junior level)

If the build context has a lot of unnecessary files (logs, large archives, node_modules, etc.), the build will:

  • run slower
  • take up more space
  • take longer to send data to Docker

That's why .dockerignore is used, to exclude the unneeded from the context.

Summary in one phrase

Build context is the set of files and folders passed into docker build, from which Docker can pull data during the image build.

If you want, in the next message I can explain .dockerignore just as briefly and with an example.

Short Answer

Interview ready
Premium

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