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