Docker
/Intermediate
Build Context
Definition
The set of files and folders located at the specific path or URL passed to the `docker build` command. These are the ONLY files the Docker daemon has access to when executing `COPY` or `ADD` commands.
Explain Like I'm New
The ingredients on the kitchen counter. If you tell the recipe to 'Add Salt', but there is no salt on the counter (in the Build Context), the build fails. Docker cannot magically reach into your other laptop folders to grab files.
Real World Example
If you run `docker build .` inside the `src` folder, the daemon bundles up the entire `src` folder and sends it to the Docker engine. If you try to `COPY ../secrets.txt` (a file outside the `src` folder), Docker throws an error because it is outside the build context.
Common Use Cases
- •Security
- •Build isolation
Interview Questions
basic
- Can a Dockerfile `COPY` a file from your laptop's 'Downloads' folder if your build context is set to your 'Documents' folder?
intermediate
- Why does running `docker build .` in the root 'C:\' drive usually crash your computer?