Skip to content

samay-hash/Docker-test-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 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 Compose โ€“ Lifecycle Management

Manage the ENTIRE lifecycle of your application with just 3 simple commands!

โ–ถ๏ธ 1. Start Services โ€” docker compose up -d

docker compose up -d

Kya 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)

โน๏ธ 2. Stop Services โ€” docker compose down

docker compose down

Kya 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

๐Ÿ”จ 3. Rebuild Services โ€” docker compose build

docker compose build

Kya 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 ๐Ÿš€

๐Ÿ“ Declarative Configuration (docker-compose.yml)

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: 3

Benefits 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-app

After Docker Compose (declarative) โœ…:

docker compose up -d    # That's it! ๐ŸŽ‰

๐ŸŽจ 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
โ”œโ”€โ”€ ๐Ÿณ 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)

๐Ÿ”ง 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

 
 
 

Contributors