Dockerfile Instructions in Docker

From the Docker cheat sheet ยท Dockerfile ยท verified Jul 2026

Dockerfile Instructions

The essential Dockerfile commands for building images

dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "server.js"]
๐Ÿ’ก Always use specific image tags (node:22-alpine) not "latest" โ€” reproducible builds
โšก Copy package.json first, then npm install, then copy source โ€” maximizes Docker layer cache
๐Ÿ“Œ ARG is build-time only; ENV persists into the running container โ€” know the difference
๐ŸŸข Run as a non-root USER in production โ€” it only takes 2 lines and prevents privilege escalation
dockerfilebuildinstructions

More Docker tasks

Back to the full Docker cheat sheet