# Building an Image — Docker Fundamentals: Images, Containers and Compose

Source: https://www.skillbyai.com/en/docker/docker-build

> 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.

```bash
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.
