Skip to content
All repositories

github.com/Bloop31/docker-url-shortener

Docker URL Shortener

A production-style multi-container backend application built to strengthen practical understanding of Docker and containerized architectures.

README

A production-style multi-container backend application built to strengthen practical understanding of Docker and containerized architectures.

This project demonstrates how independent services communicate inside a Docker network using FastAPI, Redis, Nginx, and Docker Compose.


Overview

The application allows users to shorten URLs through a FastAPI backend while Redis stores the URL mappings. Nginx acts as a reverse proxy in front of the application.

The primary goal of this project is to gain hands-on experience with:

  • Docker containerization
  • Multi-container orchestration
  • Reverse proxy configuration
  • Container networking
  • Persistent storage with volumes
  • Backend deployment workflows

Architecture

                ┌──────────────────┐
                │      Client      │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │      Nginx       │
                │  Reverse Proxy   │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │     FastAPI      │
                │   Application    │
                └────────┬─────────┘
                         │
                         ▼
                ┌──────────────────┐
                │      Redis       │
                │   URL Storage    │
                └──────────────────┘

Tech Stack

Technology Role
FastAPI Backend API
Redis In-memory database
Nginx Reverse proxy
Docker Containerization
Docker Compose Service orchestration

Project Structure

docker-url-shortener/
│
├── app/
│   ├── main.py
│   ├── requirements.txt
│   └── Dockerfile
│
├── nginx/
│   └── nginx.conf
│
├── docker-compose.yml
├── .env
└── README.md

Features

  • REST API for URL shortening
  • Multi-container Docker architecture
  • Redis-based URL storage
  • Nginx reverse proxy setup
  • Persistent storage using Docker volumes
  • Container-to-container communication
  • Production-style service separation

Docker Concepts Implemented

Dockerfile

Custom image creation for the FastAPI application.

Docker Compose

Orchestration and management of multiple services.

Docker Networking

Internal communication between:

  • FastAPI container
  • Redis container
  • Nginx container

Docker Volumes

Persistent Redis data storage.

Reverse Proxying

Nginx routing requests to backend services.

Container Isolation

Each service runs independently in its own environment.


Setup & Installation

1. Clone Repository

git clone https://github.com/YOUR_USERNAME/docker-url-shortener.git

cd docker-url-shortener

2. Build and Start Containers

docker compose up --build

3. Access Application

Open in browser:

http://localhost

API Endpoints

Base Endpoint

GET /

Returns application status.

Response

{
  "message": "Docker URL Shortener Running"
}

Shorten URL

POST /shorten

Request Body

{
  "url": "https://google.com"
}

Response

{
  "short_url": "http://localhost/abc123"
}

Retrieve Original URL

GET /{short_code}

Example

http://localhost/abc123

Response

{
  "original_url": "https://google.com"
}

Useful Docker Commands

Build Containers

docker compose build

Start Services

docker compose up

Run in Detached Mode

docker compose up -d

Stop Services

docker compose down

View Running Containers

docker ps

View Logs

docker compose logs

Access Running Container

docker exec -it fastapi_app bash

Future Enhancements

  • Real URL redirection
  • PostgreSQL integration
  • Authentication and authorization
  • URL analytics dashboard
  • Rate limiting
  • Kubernetes deployment
  • CI/CD pipeline integration
  • Load balancing with multiple app containers

Learning Outcomes

This project helped strengthen understanding of:

  • Docker fundamentals
  • Container lifecycle
  • Service orchestration
  • Reverse proxies
  • Backend deployment practices
  • Container networking
  • Persistent storage management
  • Production-style backend architecture