Dockerfile in docker

A Dockerfile is a text file with instructions to build a Docker image. Common instructions: FROM (base image), COPY (add files), RUN (execute commands), EXPOSE (declare port), CMD (default command).

Example

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

This Dockerfile creates a Node.js app image using Alpine Linux (small), installs production dependencies, copies code, and runs the server.