Docker Containers Complete Guide
Ad
What is Docker?
Docker packages applications and their dependencies into containers — lightweight, portable units that run identically everywhere. "It works on my machine" becomes "it works everywhere."
Containers vs Virtual Machines
| Container | VM | |
|---|---|---|
| Size | MBs | GBs |
| Startup | Seconds | Minutes |
| OS | Shares host | Full OS each |
A Dockerfile
FROM node:20
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
Essential Commands
docker build -t my-app . # build image
docker run -p 3000:3000 my-app # run container
docker ps # list running
docker stop <id> # stop
docker images # list images
Docker Compose (Multi-Container)
services:
web:
build: .
ports: ["3000:3000"]
db:
image: postgres:16
FAQs
Image vs container?
An image is the blueprint; a container is a running instance of it. More in our DevOps guides.
Docker vs Kubernetes?
Docker creates containers; Kubernetes orchestrates many of them at scale.
