Build a Docker image
Updated August 29, 2026
Build an image from a Dockerfile with a context directory:
docker build -t example-web:dev .
The final . is the build context; files outside it cannot normally be copied by the Dockerfile. Use a .dockerignore to keep Git metadata, dependencies, secrets, and build output out of the context.
A small Dockerfile might be:
FROM node:22-bookworm-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npm", "start"]
npm ci expects a lockfile, so this example assumes package-lock.json is present. If the project deliberately has no lockfile, choose and document an appropriate install command instead.
Choose a base tag that matches your support policy rather than relying on latest, and rebuild when dependencies or the base image need updates. Read build errors from the first failing instruction; a later COPY failure often means a path was excluded by .dockerignore. Use BuildKit/buildx features according to the Docker version installed, and do not put passwords in ARG or image layers.
Sources
related.
Ruslan Osipov
About the author