Skip to content

samay-hash/Docker-test-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Node.js Express


🌟 About This Project

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.

🎯 What Inside the Container?

┌─────────────────────────────────────────────┐
│         🐳 DOCKER CONTAINER 🐳              │
├─────────────────────────────────────────────┤
│  📦 Node.js Runtime Environment             │
│  🚀 Express.js Web Server                   │
│  📁 Frontend Files                          │
│  ⚙️  Backend APIs                           │
│  🔧 All Dependencies Pre-installed          │
└─────────────────────────────────────────────┘

📚 Amazing Docker Facts! 🤓

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

🚀 Essential Docker Commands

🔨 Building Your Docker Image

# 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 .

▶️ Running Your Container

# 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

📋 Container Management

# 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

🖼️ Image Management

# 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

🔍 Inspection Commands

# 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

🐳 Docker Compose (Multi-container)

# 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

🎨 Docker Architecture - Visualized

┌────────────────────────────────────────────────────────────────┐
│                    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

📦 Project Structure

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)

🔧 Getting Started

Prerequisites

✅ Docker installed (v20.10+)
✅ Docker Desktop running
✅ Node.js 18+ (for local development)

Quick Start

1️⃣ Clone the Repository

git clone https://github.com/samay-hash/Docker-test-app.git
cd docker-test-app

2️⃣ Build the Docker Image

docker build -t docker-test-app:latest .

3️⃣ Run the Container

docker run -d -p 3000:3000 --name my-app docker-test-app:latest

4️⃣ Access Your Application

Open your browser: 🌐 http://localhost:3000

5️⃣ View Logs

docker logs -f my-app

🐳 Dockerfile Explanation

# 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"]

🎯 What Each Line Does:

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

🚀 Docker Lifecycle - Step by Step

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!

🎓 Learning Resources

Docker Fundamentals

Advanced Topics

  • 🐳 Docker Networking
  • 📦 Docker Volumes & Storage
  • 🔐 Security in Docker
  • 📊 Container Orchestration (Kubernetes)

💡 Pro Tips & Tricks

🏃 Speed Up Build

# Use .dockerignore to skip unnecessary files
echo "node_modules" > .dockerignore
echo ".git" >> .dockerignore

🔍 Debug Containers

# 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

🎯 Optimize Image Size

# 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 .

🚀 Push to Docker Hub

# 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

🔐 Security Best Practices

✅ 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

🐛 Troubleshooting Guide

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

📊 Container vs Virtual Machine

╔═══════════════════════════════════════════════════════════╗
║                 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           ║
║                                                           ║
╚═══════════════════════════════════════════════════════════╝

🌟 Real-World Use Cases

🏢 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

🎉 Docker Commands Cheat Sheet

# 📦 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 volumes

🤝 Contributing

We welcome contributions! 🎉

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


🎊 Animation Showcase

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!

📞 Quick Links


🎯 Made with ❤️ by Docker Enthusiasts

"Build once, run anywhere!" 🐳✨

Wave Animation

    🚀
   /|\  Keep Shipping!
   / \

⭐ If you found this helpful, please star this repository! ⭐


Last Updated: January 25, 2026 Docker Version: 20.10+ Node.js Version: 18+

About

First Docker Test_App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published