Building a Wedding Photo Gallery Bot: Part 1 – Infrastructure Setup with Docker, Coolify & PostgreSQL

December 26, 2025
•
Rabra Hierpa
#coolify#infra#react#telegram_bot#vps
Building a Wedding Photo Gallery Bot: Part 1 - Infrastructure Setup with Docker, Coolify & PostgreSQL

A complete guide to setting up a self-hosted infrastructure for a Telegram-powered wedding photo gallery


Introduction

Planning a wedding in 2025 means embracing technology to make memories last forever. Instead of relying on expensive third-party platforms like Supabase ($25/month) or cloud hosting, I built a self-hosted wedding photo gallery powered by a Telegram bot, deployed on a Hostinger VPS using Coolify for just $6-11/month.

This is Part 1 of a 3-part series where I’ll walk you through the complete infrastructure setup. By the end of this article, you’ll have:

  • ✅ A running PostgreSQL database in Docker
  • ✅ Coolify PaaS configured for deployment
  • ✅ Database connection via DBeaver
  • ✅ Understanding of Docker networking

What we’re building: A wedding photo gallery where guests can upload photos via Telegram bot, which automatically appear on a beautiful web gallery in real-time.


Why Self-Host? Cost Comparison

SolutionMonthly CostNotes
Supabase + Vercel$25+Storage limits, scaling costs
AWS/GCP$30-50+Complex setup, hidden costs
VPS + Coolify$6-11Full control, unlimited storage

Our choice: Hostinger VPS + Coolify = Professional deployment at 75% cost savings.


Tech Stack Overview

Core Infrastructure

  • VPS: Hostinger (or any provider)
  • OS: Ubuntu 22.04 LTS
  • Container Platform: Docker + Docker Compose
  • PaaS: Coolify (self-hosted Heroku alternative)
  • Database: PostgreSQL 16

Development Tools

  • Database Client: DBeaver Community Edition
  • SSH Client: Terminal (macOS/Linux) or PuTTY (Windows)
  • Version Control: Git

Part 1: Setting Up Your VPS

Step 1: Provision Your VPS

Recommended Specs (600+ guests):

  • CPU: 2 cores minimum
  • RAM: 4GB minimum (8GB recommended)
  • Storage: 50GB SSD minimum
  • OS: Ubuntu 22.04 LTS

Where to buy:

  • Hostinger: $5-10/month
  • DigitalOcean: Droplet $12/month
  • Vultr: High-frequency compute $6/month

Step 2: Initial Server Setup

SSH into your VPS:

ssh root@your-vps-ip

Update the system:

apt update && apt upgrade -y

Install required packages:

apt install -y curl wget git ufw

Configure firewall:

# Allow SSH
ufw allow 22/tcp

# Allow HTTP/HTTPS
ufw allow 80/tcp
ufw allow 443/tcp

# Enable firewall
ufw enable

Part 2: Installing Docker

Why Docker?

Docker containerizes our application, making deployment consistent across environments. It ensures:

  • Isolation: Each service runs independently
  • Portability: Deploy anywhere
  • Reproducibility: Same environment every time

Installation Steps

Install Docker Engine:

# Add Docker's official GPG key
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

# Verify installation
docker --version

Install Docker Compose:

# Download latest version
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# Make executable
chmod +x /usr/local/bin/docker-compose

# Verify
docker-compose --version

Key Docker Concepts

Container: Running instance of an application
Image: Blueprint for containers
Volume: Persistent storage for containers
Network: Communication layer between containers


Part 3: Installing Coolify

What is Coolify?

Coolify is a self-hosted PaaS (Platform as a Service) that provides:

  • 🚀 One-click deployments from GitHub
  • 🗄️ Built-in database management
  • 🔒 Automatic SSL certificates (Let’s Encrypt)
  • 📊 Resource monitoring
  • 🔄 Zero-downtime deployments

Think: Heroku + Railway + Netlify, but self-hosted and free.

Installation

Run the installation script:

curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash

This will:

  1. Install Docker (if not present)
  2. Set up Coolify containers
  3. Configure reverse proxy (Traefik)
  4. Create admin user

Access Coolify

After installation completes (~5 minutes):

# Get your Coolify URL
echo "http://$(curl -s ifconfig.me):8000"

Open in browser and complete setup:

  1. Set admin email
  2. Set strong password
  3. Configure server settings

Important: Immediately configure HTTPS by adding your domain in Coolify settings.


Part 4: Creating PostgreSQL Database

Why PostgreSQL?

PostgreSQL is our choice because:

  • ✅ Robust: ACID-compliant, handles concurrent writes
  • ✅ Scalable: Supports millions of rows efficiently
  • ✅ Feature-rich: JSON support, full-text search, indexes
  • ✅ Open-source: No licensing costs

Create Database in Coolify

Step 1: In Coolify Dashboard:

  1. Click Resources → Add Resource
  2. Select Database → PostgreSQL
  3. Configure:
    • Name: wedding-gallery-db
    • Version: PostgreSQL 16 (latest stable)
    • Username: postgres (default, Coolify auto-creates)
    • Password: Auto-generated (copy this!)
    • Database: postgres (default database)
  4. Click Create

Step 2: Wait for deployment (1-2 minutes)

The container will be created with:

Container: wedding-gallery-db
Port: 5432 (internal)
Network: coolify (Docker network)

Understanding Connection Strings

Coolify provides two connection strings:

Internal (for apps in Coolify)

postgresql://postgres:AUTO_GENERATED_PASSWORD@wedding-gallery-db:5432/postgres

Public (for external access like DBeaver)

postgresql://postgres:AUTO_GENERATED_PASSWORD@your-vps-ip:5432/postgres

Key differences:

  • Internal: Uses Docker network DNS (wedding-gallery-db)
  • Public: Uses VPS IP address, exposes port to internet

Critical Configuration Notes

❌ Common Mistakes:

# Wrong: Coolify doesn't use these custom values by default
DATABASE_URL=postgresql://wedding_user:password@localhost:5432/wedding_gallery

# Correct: Use Coolify's defaults
DATABASE_URL=postgresql://postgres:xK9mP2nL4vQ7sT1w@wedding-gallery-db:5432/postgres

Important Rules:

  1. Username is always postgres (Coolify default)
  2. Password is auto-generated (copy from Coolify UI)
  3. Database is always postgres (or create custom)
  4. Host is service name for internal, VPS IP for external
  5. Always append /postgres at the end!

Part 5: Connecting with DBeaver

Why DBeaver?

DBeaver is a universal database client that provides:

  • 📊 Visual query builder
  • 🔍 Database schema explorer
  • 📝 SQL editor with autocomplete
  • 🎨 ER diagrams

Installation

macOS:

brew install --cask dbeaver-community

Windows:
Download from dbeaver.io

Linux:

sudo snap install dbeaver-ce

Connecting to PostgreSQL

Step 1: Expose PostgreSQL port in Coolify

In Coolify → Database → wedding-gallery-db:

  1. Go to Ports tab
  2. Enable Public Port
  3. Map 5432:5432

Security Warning: This exposes PostgreSQL to the internet! Options:

  • Use SSH tunnel (recommended for production)
  • Whitelist only your IP in firewall
  • Use strong passwords (Coolify does this by default)

Step 2: Create New Connection in DBeaver

  1. Open DBeaver → Database → New Database Connection
  2. Select PostgreSQL
  3. Enter connection details:
Host: your-vps-ip
Port: 5432
Database: postgres
Username: postgres
Password: [paste from Coolify]

SSL: Disable (or configure certificate)
  1. Test Connection → Finish

Verify Connection

Run a test query:

-- Check PostgreSQL version
SELECT version();

-- List all databases
l

-- Create a test table
CREATE TABLE test (
    id SERIAL PRIMARY KEY,
    message TEXT
);

-- Insert test data
INSERT INTO test (message) VALUES ('Connection successful!');

-- Query test data
SELECT * FROM test;

-- Clean up
DROP TABLE test;

Part 6: Understanding Docker Networking

How Containers Communicate

When you create resources in Coolify, they’re all placed on the same Docker network:

docker network ls
# OUTPUT:
# NETWORK ID     NAME       DRIVER    SCOPE
# abc123def456   coolify    bridge    local

Internal vs External Access

Scenario 1: App → Database (Internal)

# ✅ Works (same Docker network)
DATABASE_URL=postgresql://postgres:password@wedding-gallery-db:5432/postgres

Scenario 2: Your Computer → Database (External)

# ✅ Works (public IP + exposed port)
DATABASE_URL=postgresql://postgres:password@123.45.67.89:5432/postgres

Scenario 3: App → Database (Wrong)

# ❌ Fails (localhost in container is the container itself)
DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres

Docker Networking Best Practices

  1. Use service names for internal communication
  2. Minimize port exposure for security
  3. Use Docker networks to isolate services
  4. Leverage Docker DNS for automatic service discovery

Inspecting Your Network

# View all containers on Coolify network
docker network inspect coolify

# Check running containers
docker ps

# View container logs
docker logs wedding-gallery-db

# Execute commands in container
docker exec -it wedding-gallery-db psql -U postgres

# Inside PostgreSQL:
dt    # List tables
du    # List users
q     # Quit

Part 7: Database Schema Design

Now that our infrastructure is ready, let’s design our database schema.

Schema Overview

Our wedding gallery needs 4 main tables:

  1. guests: Telegram users who upload photos
  2. photos: Uploaded images metadata
  3. wishes: Guest wishes for the couple
  4. likes: Photo likes from web users

Creating the Schema

In DBeaver, run this SQL:

-- Create Guests table
CREATE TABLE guests (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    telegram_user_id BIGINT NOT NULL UNIQUE,
    telegram_username TEXT,
    first_name TEXT NOT NULL,
    last_name TEXT,
    registered_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    in_wedding_group BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create Photos table
CREATE TABLE photos (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    guest_id UUID NOT NULL REFERENCES guests(id) ON DELETE CASCADE,
    storage_path TEXT NOT NULL,
    public_url TEXT NOT NULL,
    telegram_file_id TEXT NOT NULL,
    group_message_id TEXT,
    caption TEXT,
    uploaded_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create Wishes table
CREATE TABLE wishes (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    guest_id UUID NOT NULL REFERENCES guests(id) ON DELETE CASCADE,
    message TEXT NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create Likes table
CREATE TABLE likes (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
    guest_id UUID REFERENCES guests(id) ON DELETE CASCADE,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    UNIQUE(photo_id, guest_id)
);

-- Create indexes for performance
CREATE INDEX idx_guests_telegram_user_id ON guests(telegram_user_id);
CREATE INDEX idx_photos_guest_id ON photos(guest_id);
CREATE INDEX idx_photos_uploaded_at ON photos(uploaded_at DESC);
CREATE INDEX idx_wishes_guest_id ON wishes(guest_id);
CREATE INDEX idx_wishes_created_at ON wishes(created_at DESC);
CREATE INDEX idx_likes_photo_id ON likes(photo_id);
CREATE INDEX idx_likes_guest_id ON likes(guest_id);

Schema Design Decisions

Why UUID for IDs?

  • Globally unique
  • Non-sequential (security)
  • Easier to merge data from multiple sources

Why BIGINT for telegram_user_id?

  • Telegram user IDs are large integers
  • Can exceed JavaScript’s safe integer range

Why ON DELETE CASCADE?

  • When a guest is deleted, all their photos/wishes/likes are auto-deleted
  • Maintains referential integrity

Why TIMESTAMP WITH TIME ZONE?

  • Stores timezone information
  • Critical for international guests

Part 8: Testing Your Setup

Verification Checklist

Run through this checklist:

  • [ ] VPS is accessible via SSH
  • [ ] Docker is installed and running
  • [ ] Coolify dashboard is accessible
  • [ ] PostgreSQL container is running
  • [ ] DBeaver can connect to database
  • [ ] Database schema is created
  • [ ] All indexes are present

Quick Test Script

SSH into your VPS and run:

#!/bin/bash

echo "=== Docker Status ==="
docker --version

echo -e "n=== Coolify Containers ==="
docker ps | grep coolify

echo -e "n=== Database Container ==="
docker ps | grep wedding-gallery-db

echo -e "n=== Database Connection Test ==="
docker exec wedding-gallery-db psql -U postgres -c "SELECT 'Database OK' as status;"

echo -e "n=== Database Tables ==="
docker exec wedding-gallery-db psql -U postgres -d postgres -c "dt"

echo -e "n✅ Infrastructure is ready!"

Troubleshooting Common Issues

Issue 1: Can’t Connect to Coolify

Symptoms: Browser can’t load Coolify dashboard

Solutions:

# Check if Coolify is running
docker ps | grep coolify

# Restart Coolify
docker restart $(docker ps -q --filter name=coolify)

# Check firewall
ufw status

# Allow Coolify port
ufw allow 8000/tcp

Issue 2: Database Connection Refused

Symptoms: DBeaver shows “Connection refused”

Solutions:

# Verify database is running
docker ps | grep wedding-gallery-db

# Check database logs
docker logs wedding-gallery-db

# Verify port is exposed
docker port wedding-gallery-db

# Test connection from VPS
docker exec wedding-gallery-db psql -U postgres -c "SELECT 1"

Issue 3: Wrong Connection String

Symptoms: “database does not exist” or “authentication failed”

Solutions:

  • ✅ Verify username is postgres (not wedding_user)
  • ✅ Copy password exactly from Coolify (case-sensitive)
  • ✅ Use service name (wedding-gallery-db) not localhost
  • ✅ Append /postgres at the end of URL

Security Best Practices

1. Secure Your VPS

# Change default SSH port
nano /etc/ssh/sshd_config
# Change: Port 22 → Port 2222
systemctl restart sshd

# Disable root login
PermitRootLogin no

# Use SSH keys instead of passwords
ssh-keygen -t ed25519

2. Secure PostgreSQL

# Don't expose PostgreSQL port publicly
# Use SSH tunnel instead:
ssh -L 5432:localhost:5432 root@your-vps-ip

# Then connect DBeaver to localhost:5432

3. Environment Variables

Never commit sensitive data to Git:

# .env.example (commit this)
DATABASE_URL=postgresql://user:password@host:5432/db

# .env (never commit!)
DATABASE_URL=postgresql://postgres:xK9mP2nL4vQ7sT1w@wedding-gallery-db:5432/postgres

4. Regular Backups

# Create backup script
cat > /root/backup-db.sh << 'EOF'
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
docker exec wedding-gallery-db pg_dump -U postgres postgres > /backups/wedding_$DATE.sql
find /backups -name "wedding_*.sql" -mtime +7 -delete
EOF

chmod +x /root/backup-db.sh

# Schedule daily backups
crontab -e
# Add: 0 2 * * * /root/backup-db.sh

Performance Optimization

Database Indexing

We’ve already added indexes in our schema. Monitor performance:

-- Check index usage
SELECT
    schemaname,
    tablename,
    indexname,
    idx_scan as index_scans
FROM pg_stat_user_indexes
ORDER BY idx_scan DESC;

-- Find missing indexes
SELECT * FROM pg_stat_user_tables WHERE idx_scan = 0;

Connection Pooling

For high traffic, use connection pooling:

# Install PgBouncer in Coolify
# Resources → Add Resource → Database → PgBouncer

Cost Breakdown

ItemMonthly CostNotes
Hostinger VPS (4GB RAM)$8-10You already have this
Domain (.com)$1.25$15/year
SSL Certificate$0Let’s Encrypt (free)
Coolify$0Self-hosted
PostgreSQL$0Self-hosted
Total~$10/monthvs $25+ with Supabase

Savings: $180/year minimum!


What’s Next?

Congratulations! You now have:

  • ✅ Production-ready VPS infrastructure
  • ✅ PostgreSQL database running in Docker
  • ✅ Coolify PaaS for easy deployments
  • ✅ Database access via DBeaver
  • ✅ Optimized schema with indexes

In Part 2, we’ll build the Telegram bot that:

  • Registers guests
  • Handles photo uploads
  • Stores photos in the database
  • Manages group chat integration
  • Implements wishes and likes features

In Part 3, we’ll deploy the Next.js web application, configure the custom domain, and implement scaling optimizations for 600+ wedding guests.


Resources


Questions?

Drop your questions in the comments below! I’ll be happy to help you set up your own self-hosted wedding gallery.

Next Article: Building the Telegram Bot (Part 2) 


Built with ❤️ for an unforgettable celebration


R

Rabra Hierpa

Software Engineer, GIS Developer, and FOSS enthusiast sharing insights on web development, GIS technologies, and open-source tools.