Virtual Machines vs Containers
Virtual Machines (VMs) virtualize full hardware stacks, including guest operating systems, which are resource-heavy. Containers share the host OS kernel and isolate processes using namespaces and cgroups, making them lightweight and fast to start.
Dockerfiles and Images
A Dockerfile specifies the steps required to build a container image. Images are immutable, layered templates containing application source code, runtime engines, and system libraries.
DOCKERFILE Snippet
dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "src/server.js"]