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 --build┌────────────────────────────────────────────────────────────────┐
│ 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
├── 📄 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 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+