Welcome to the Docker Test App - A modern containerized Node.js application that demonstrates the power of Docker! This project showcases how to dockerize a Node.js application with Express backend, making it portable and scalable across any environment.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ณ DOCKER CONTAINER ๐ณ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐ฆ Node.js Runtime Environment โ
โ ๐ Express.js Web Server โ
โ ๐ Frontend Files โ
โ โ๏ธ Backend APIs โ
โ ๐ง All Dependencies Pre-installed โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Did You Know?
- ๐ณ Docker was released in 2013 and revolutionized containerization
- ๐ Over 20 million developers use Docker worldwide
- โก Containers start in milliseconds (vs minutes for VMs)
- ๐ Docker uses Linux namespaces for isolation
- ๐ Docker Hub has 8+ million pre-built images
- ๐พ Containers are typically 100x lighter than VMs
- ๐ Netflix uses Docker to manage thousands of containers
- ๐ Docker images are immutable (reproducible across systems)
- ๐ฏ One container per process is the Docker philosophy
- ๐ฆ Docker images can be layered for efficiency
# Build the Docker image
docker build -t docker-test-app:latest .
# Build with custom tag
docker build -t docker-test-app:v1.0 .
# Build without cache
docker build --no-cache -t docker-test-app:latest .# Run the container in background
docker run -d -p 3000:3000 --name my-app docker-test-app:latest
# Run with environment variables
docker run -d -p 3000:3000 -e NODE_ENV=production docker-test-app:latest
# Run with volume mounting (for development)
docker run -d -p 3000:3000 -v $(pwd):/app docker-test-app:latest
# Run and access terminal
docker run -it docker-test-app:latest /bin/bash# List all running containers
docker ps
# List all containers (including stopped)
docker ps -a
# View container logs
docker logs my-app
# View live logs
docker logs -f my-app
# Stop a container
docker stop my-app
# Start a stopped container
docker start my-app
# Remove a container
docker rm my-app
# Remove all stopped containers
docker container prune# List all images
docker images
# Remove an image
docker rmi docker-test-app:latest
# Tag an image
docker tag docker-test-app:latest username/docker-test-app:v1.0
# Push to Docker Hub
docker push username/docker-test-app:v1.0
# Pull an image
docker pull username/docker-test-app:v1.0
# Remove dangling images
docker image prune# Inspect container details
docker inspect my-app
# View container stats
docker stats my-app
# Execute command in running container
docker exec -it my-app bash
# View container's processes
docker top my-app
# View changes in container
docker diff my-app# Build and start all services
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# Rebuild services
docker-compose up -d --buildManage the ENTIRE lifecycle of your application with just 3 simple commands!
docker compose up -dKya hota hai (What happens):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ $ docker compose up -d โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Step 1 โ Reads docker-compose.yml โ
โ Step 2 โ Builds image (if not already built) โ
โ Step 3 โ Creates a network for the services โ
โ Step 4 โ Creates & starts the container(s) โ
โ Step 5 โ Runs in detached mode (-d = background) โ
โ โ
โ โ
Result: App running at http://localhost:3000 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Flag | Meaning |
|---|---|
-d |
Detached mode โ container runs in the background, terminal stays free |
No -d |
Logs stream directly in terminal (Ctrl+C to stop) |
docker compose downKya hota hai (What happens):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ $ docker compose down โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Step 1 โ Stops all running containers โ
โ Step 2 โ Removes the containers โ
โ Step 3 โ Removes the default network โ
โ โ
โ โ ๏ธ Images & volumes are PRESERVED (not deleted) โ
โ โ
Result: Everything cleanly stopped โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Variant | What it does |
|---|---|
docker compose down |
Stops & removes containers + network |
docker compose down -v |
Also removes volumes (database data!) |
docker compose down --rmi all |
Also removes images |
docker compose buildKya hota hai (What happens):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ $ docker compose build โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Step 1 โ Reads Dockerfile for each service โ
โ Step 2 โ Rebuilds images from scratch (uses cache) โ
โ Step 3 โ New image is ready to be started โ
โ โ
โ ๐ก Use when: Code changed, dependencies updated, โ
โ or Dockerfile modified โ
โ โ
Result: Fresh image built, ready for `up -d` โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Variant | What it does |
|---|---|
docker compose build |
Builds with cache (fast) |
docker compose build --no-cache |
Full rebuild (ignores cache) |
docker compose up -d --build |
Build + Start in one command ๐ |
The YAML file provides a clear and concise way to define your application's services โ eliminating the need for manual configuration!
version: "3.8"
services:
web: # ๐ท๏ธ Service name
build: . # ๐ Build from Dockerfile in current dir
ports:
- "3000:3000" # ๐ Map host:container ports
environment:
- NODE_ENV=production # ๐ Environment variables
restart: unless-stopped # ๐ Auto-restart on crash
healthcheck: # ๐ Monitor container health
test: ["CMD", "wget", "--spider", "http://localhost:3000/"]
interval: 30s
timeout: 10s
retries: 3Benefits of Declarative Configuration:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
ONE FILE defines everything โ docker-compose.yml โ
โ โ
NO more remembering long docker run commands โ
โ โ
Version controlled โ track changes in Git โ
โ โ
Team friendly โ everyone runs the same setup โ
โ โ
Environment variables โ manage configs cleanly โ
โ โ
Reproducible โ same result every time, everywhere โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Before Docker Compose (manual) โ:
docker build -t my-app .
docker run -d -p 3000:3000 -e NODE_ENV=production --restart unless-stopped --name my-app my-appAfter Docker Compose (declarative) โ :
docker compose up -d # That's it! ๐โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ YOUR MACHINE (HOST OS) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ DOCKER ENGINE (Daemon) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ CONTAINER 1 โ โ CONTAINER 2 โ โ โ
โ โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ โ
โ โ โ โ App Code โ โ โ โ App Code โ โ โ โ
โ โ โ โโโโโโโโโโโโโค โ โ โโโโโโโโโโโโโค โ โ โ
โ โ โ โ Libraries โ โ โ โ Libraries โ โ โ โ
โ โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ โ
โ โ โ (Isolated) โ โ (Isolated) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Shared Linux Kernel (lightweight) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โจ Key Benefits:
โ
Isolated environments
โ
Minimal overhead
โ
Fast deployment
โ
Consistent across platforms
docker-test-app/
โโโ ๐ณ Dockerfile # Container blueprint
โโโ ๐ณ docker-compose.yml # Compose lifecycle config
โโโ ๐ README.md # This awesome file!
โโโ ๐ package.json # Project dependencies
โโโ ๐ index.js # Main application
โโโ ๐ backend/
โโโ ๐ package.json # Backend dependencies
โโโ ๐ server.js # Backend server (if exists)
โ
Docker installed (v20.10+)
โ
Docker Desktop running
โ
Node.js 18+ (for local development)git clone https://github.com/samay-hash/Docker-test-app.git
cd docker-test-appdocker build -t docker-test-app:latest .docker run -d -p 3000:3000 --name my-app docker-test-app:latestOpen your browser: ๐ http://localhost:3000
docker logs -f my-app# Use official Node.js runtime as base image
FROM node:18-alpine
# Set working directory in container
WORKDIR /app
# Copy package.json files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy application code
COPY . .
# Expose port
EXPOSE 3000
# Health check (optional)
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node healthcheck.js
# Start application
CMD ["node", "index.js"]| Command | Purpose |
|---|---|
FROM |
Specifies base image (lightweight Alpine) |
WORKDIR |
Sets the working directory in container |
COPY |
Copies files from host to container |
RUN |
Executes commands during build |
EXPOSE |
Documents which ports the app uses |
HEALTHCHECK |
Monitors container health |
CMD |
Default command when container starts |
1๏ธโฃ WRITE CODE
โโ Create your application files
2๏ธโฃ CREATE DOCKERFILE
โโ Define container blueprint
3๏ธโฃ BUILD IMAGE
$ docker build -t app:latest .
โโ Creates immutable image snapshot
4๏ธโฃ RUN CONTAINER
$ docker run -d -p 3000:3000 app:latest
โโ Starts isolated container instance
5๏ธโฃ MANAGE & SCALE
$ docker ps, docker logs, docker stats
โโ Monitor and manage running containers
6๏ธโฃ PUSH TO REGISTRY
$ docker push username/app:latest
โโ Share image globally (Docker Hub)
7๏ธโฃ DEPLOY ANYWHERE
โจ Cloud โข On-Premise โข Edge Devices
โโ Run same container anywhere!
- ๐ฅ Docker Documentation
- ๐ Docker Best Practices
- ๐ Docker Hub Registry
- ๐ณ Docker Networking
- ๐ฆ Docker Volumes & Storage
- ๐ Security in Docker
- ๐ Container Orchestration (Kubernetes)
# Use .dockerignore to skip unnecessary files
echo "node_modules" > .dockerignore
echo ".git" >> .dockerignore# Open shell in running container
docker exec -it my-app /bin/sh
# Inspect image layers
docker history docker-test-app:latest
# View real-time resource usage
docker stats --no-stream# Use Alpine images (smaller)
FROM node:18-alpine
# Multi-stage builds for production
FROM node:18 AS builder
# ... build steps ...
FROM node:18-alpine
COPY --from=builder /app .# Login to Docker Hub
docker login
# Tag your image
docker tag docker-test-app:latest username/docker-test-app:v1.0
# Push the image
docker push username/docker-test-app:v1.0โ
Use specific image tags (not latest)
โ
Keep base images updated
โ
Don't run as root in containers
โ
Scan images for vulnerabilities
โ
Use secrets for sensitive data
โ
Implement resource limits
โ
Use read-only filesystems when possible| Issue | Solution |
|---|---|
| Port already in use | docker run -p 8080:3000 app |
| Container exits immediately | docker logs container-id |
| High memory usage | docker stats + optimize code |
| Image too large | Use Alpine, multi-stage build |
| Permission denied | sudo or add user to docker group |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CONTAINERS vs VMs โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ โ
โ CONTAINERS โ VIRTUAL MACHINES โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Lightweight (MB) โ Heavy (GB) โ
โ Fast startup (ms) โ Slow startup (min) โ
โ Share OS kernel โ Full OS per VM โ
โ High density โ Low density โ
โ Easy to scale โ Complex to scale โ
โ Microservices friendly โ Monolith friendly โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ข ENTERPRISE
โโ Microservices architecture
โโ CI/CD pipelines
โโ Multi-cloud deployment
โโ DevOps automation
๐ STARTUPS
โโ Rapid development
โโ Easy scaling
โโ Cost efficiency
โโ Quick deployment
๐ฎ GAMING
โโ Game servers
โโ Backend services
โโ Database clustering
โโ Load balancing
๐ DATA SCIENCE
โโ ML model deployment
โโ Jupyter notebooks
โโ Data pipelines
โโ Reproducible research
# ๐ฆ IMAGE COMMANDS
docker images # List images
docker build -t name:tag . # Build image
docker rmi image-id # Remove image
docker push username/image:tag # Push to registry
docker pull username/image:tag # Pull from registry
# ๐ณ CONTAINER COMMANDS
docker run -d image:tag # Run container
docker ps # List running containers
docker ps -a # List all containers
docker stop container-id # Stop container
docker start container-id # Start container
docker rm container-id # Remove container
docker logs container-id # View logs
docker exec -it container-id bash # Enter container
# ๐ง UTILITY COMMANDS
docker inspect container-id # Inspect container
docker stats container-id # View statistics
docker top container-id # View processes
docker port container-id # View port mappings
docker network ls # List networks
docker volume ls # List volumesWe welcome contributions! ๐
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Docker Magic in Action:
Step 1: BUILD
โโโโโโโโโโโโ
โ Dockerfileโ โโ> docker build
โโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Docker Image โ (read-only snapshot)
โโโโโโโโโโโโโโโโโโโโ
โ
โผ
Step 2: RUN
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ณ Running Container โ ๐ ALIVE!
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Your Application Running โ โ
โ โ โ
All dependencies ready โ โ
โ โ โ
Network configured โ โ
โ โ โ
Volumes mounted โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Step 3: DEPLOY
โ๏ธ Docker Hub, AWS, Azure, GCP, On-Premise
๐ Run ANYWHERE without changes!
- ๐ Docker Official Website
- ๐ Docker Documentation
- ๐ GitHub Repository
- ๐ฌ Docker Community
- ๐ Docker Learning Path
"Build once, run anywhere!" ๐ณโจ
๐
/|\ Keep Shipping!
/ \
โญ If you found this helpful, please star this repository! โญ
Last Updated: January 25, 2026 Docker Version: 20.10+ Node.js Version: 18+