Docker???
Docker Image
A Docker image is a built, read-only package.
It contains:
- OS layer (Linux)
- runtime (Node, etc.)
- app code
- dependencies
- start command
Key points:
- Images do not run
- Images are templates
- Images are created using a Dockerfile
Example:
docker build -t my-app .This creates an image.
Docker Container
A Docker container is a running instance of an image.
Key points:
- Containers run
- Containers are isolated processes
- You can start, stop, restart, delete them
- Multiple containers can come from one image
Example:
docker run my-appThis starts a container from the image.
Relationship (important)
Dockerfile → Image → Container- Dockerfile defines how to build
- Image is what gets built
- Container is what actually runs
What is a Dockerfile?
A Dockerfile is a text file that tells Docker how to build an image (step by step).
Used to:
- define runtime (Node, OS, etc.)
- copy code
- install dependencies
- start the app
No extension because Docker looks for the exact name Dockerfile by convention.
server/Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3001
CMD ["node", "server.js"]What this does:
- Uses a lightweight Node image
- Installs dependencies
- Copies application code
- Starts the API server
Why order matters in Dockerfile
Docker builds line by line and caches layers.
Get Alember Shreesh’s stories in your inbox
Join Medium for free to get updates from this writer.
If a line changes:
- that line and everything after it rebuilds
That’s why deps are copied before app code.
How Docker caching works
- Each instruction = one layer
- If nothing changed → Docker reuses cached layer
- If something changed → rebuild from that point
Result:
- Faster builds
- Smaller rebuild scope
Dockerfile vs docker-compose.yml
- Dockerfile → how to build one image
- docker-compose.yml → how to run multiple containers together
When to use what
- Only Dockerfile → single service
- Dockerfile + Compose → full-stack app
- Only Compose → using prebuilt images
Docker Compose:
Docker Compose defines how containers are started, connected, configured, and stopped as a group.
services:
backend:
build: ./server
container_name: api
ports:
- "3001:3001"
env_file:
- ./server/.env
restart: unless-stopped
frontend:
build: ./client
container_name: web
ports:
- "80:80"
depends_on:
- backend
restart: unless-stoppedThis keeps frontend and backend isolated but connected.
What actually happens
When you run:
docker compose upDocker Compose:
1)Looks at docker-compose.yml
2) For each service:
- builds an image (if
build:is defined) OR - pulls an image (if
image:is defined)
3) creates containers from those images
4) runs the containers together
Example:
services:
backend:
build: ./server
frontend:
image: nginxWhat Compose does:
- Builds one image for
backend - Pulls one image for
frontend - Runs two containers










