categories.containers-platform Basic
What is the difference between Docker containers and VMs? What is the relationship between Image and Container?
Containers vs Virtual Machines
| Characteristic | Virtual Machine | Container |
|---|---|---|
| Isolation level | OS-level | Process-level |
| Startup time | Minutes | Seconds |
| Size | GBs | MBs |
| Resource overhead | High (each VM has full OS) | Low (shares host OS kernel) |
| Portability | Lower | High |
Image vs Container
Image: A read-only filesystem snapshot containing the application, dependencies, and configuration. It is a static template.
Container: A running instance of an image, with an added writable layer. It is a dynamic runtime state.
Analogy: An image is like source code, a container is like a running process.
Basic Dockerfile Structure
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "server.js"]
Layer Caching
Each Dockerfile instruction creates a layer. Docker caches unchanged layers. Place frequently changing instructions (like COPY . .) at the end so static dependency layers can be reused from cache, speeding up builds.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
