Build context

The build context is the folder given to docker build, often the final dot. Its files are sent to the builder, and they are the only files COPY can read.

How it works

docker build -t api ./api sends ./api, and COPY paths are relative to it, never to your current folder. The build output shows "transferring context" with its size. A file outside the context cannot be copied, not even with ../.

What breaks

Building from the root of the repository sends everything: .git, node_modules, local databases, .env files. Builds slow down, and COPY . . puts those files, secrets included, inside the image. Narrow the context or add a .dockerignore.

In a terminal

docker build -t orders-api ./api
docker build -t orders-api -f api/Dockerfile api

See it break, then fix it

Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.