Docs / Containers & Docker / How to Create a Custom Dockerfile

How to Create a Custom Dockerfile

By Admin · Feb 25, 2026 · Updated Apr 24, 2026 · 489 views · 1 min read

Dockerfiles define how to build custom container images.

Basic Dockerfile

FROM node:20-slim\n\nWORKDIR /app\n\nCOPY package*.json ./\nRUN npm ci --only=production\n\nCOPY . .\n\nEXPOSE 3000\n\nCMD ["node", "app.js"]

Build

docker build -t myapp:latest .

Run

docker run -d -p 3000:3000 --name myapp myapp:latest

Best Practices

  • Use slim/alpine base images
  • Copy package files first for better layer caching
  • Use .dockerignore to exclude node_modules, .git, etc.
  • Run as non-root user with USER instruction
  • Use multi-stage builds for compiled languages

Was this article helpful?