Lesson 8 / 28

Building an Image

Build an image with docker build, understand the build context and layer caching.

docker build

-t tags the image with a name. The trailing . is the build context — the directory Docker can see and copy from.

docker build -t my-app:1.0 .
docker run -d my-app:1.0

Layers & caching

Each instruction creates a layer. Docker caches layers and reuses them if nothing above them changed — that's why copying package.json and running npm install before copying the rest of the code speeds up rebuilds.