# PeerTube Video Platform

> PeerTube federated video hosting platform with ActivityPub support.

- Category: Media & Entertainment
- Difficulty: advanced
- Components: peertube, postgres, redis
- Tags: peertube, video, federated, youtube-alternative, activitypub
- Source: https://docker.recipes/media/peertube-video

## Overview

PeerTube is a decentralized video hosting platform that emerged as an open-source alternative to centralized services like YouTube. Built by Framasoft and launched in 2018, PeerTube leverages ActivityPub protocol for federation and WebTorrent technology for peer-to-peer video distribution. This approach reduces server bandwidth costs while creating a network of interconnected video platforms that can share content and audiences across instances. PostgreSQL serves as PeerTube's primary database, handling complex video metadata, user accounts, federation data, and comment systems with the reliability and ACID compliance required for content management platforms. Redis provides high-speed caching for video thumbnails, user sessions, and federation message queues, while also managing real-time features like live streaming coordination and background job processing. Content creators, educational institutions, and organizations seeking video hosting independence will find this stack particularly valuable for building sustainable video communities without relying on corporate platforms. The federation capabilities mean your instance can connect with thousands of other PeerTube servers worldwide, dramatically expanding your potential audience while maintaining full control over your content and community policies.

## Features

- ActivityPub federation allowing content sharing and discovery across PeerTube instances worldwide
- WebTorrent peer-to-peer video streaming reducing server bandwidth costs through viewer participation
- RTMP live streaming support on port 1935 with Redis-coordinated real-time chat and viewer management
- PostgreSQL-powered advanced video categorization with tags, channels, playlists, and full-text search
- Redis-cached video transcoding queue management for multiple resolution and format processing
- Federated comment system allowing users from other ActivityPub platforms like Mastodon to interact
- Built-in video statistics and analytics stored in PostgreSQL with Redis performance optimization
- Multi-language subtitle support with PostgreSQL storage and Redis caching for fast retrieval

## Use cases

- Educational institutions hosting course videos with controlled access and student interaction features
- Independent content creators building audiences across federated PeerTube networks
- Organizations requiring GDPR-compliant video hosting with full data control and European server locations
- Community groups sharing event recordings and live streaming local meetings or conferences
- Businesses hosting product demonstrations and training videos without YouTube's advertising and algorithm constraints
- News organizations publishing video content with federation reach while maintaining editorial independence
- Gaming communities streaming gameplay and tournaments with integrated chat and community features

## Prerequisites

- Minimum 4GB RAM (2GB for PostgreSQL, 1GB for PeerTube transcoding, 512MB for Redis caching)
- Docker host with ports 9000, 1935, 80, and 443 accessible for web interface and RTMP streaming
- Valid domain name and SSL certificate for PEERTUBE_HOSTNAME federation requirements
- Understanding of ActivityPub federation concepts and PeerTube instance administration
- Storage planning for video files as PeerTube data volume will grow significantly with uploads
- SMTP server configuration knowledge for user registration and notification emails

## docker-compose.yml

```yaml
services:
  peertube:
    image: chocobozzz/peertube:production-bookworm
    container_name: peertube
    environment:
      - PEERTUBE_DB_USERNAME=${POSTGRES_USER}
      - PEERTUBE_DB_PASSWORD=${POSTGRES_PASSWORD}
      - PEERTUBE_DB_SSL=false
      - PEERTUBE_DB_HOSTNAME=postgres
      - PEERTUBE_REDIS_HOSTNAME=redis
      - PEERTUBE_WEBSERVER_HOSTNAME=${PEERTUBE_HOSTNAME}
      - PEERTUBE_WEBSERVER_PORT=443
      - PEERTUBE_WEBSERVER_HTTPS=true
      - PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback", "172.17.0.0/16"]
      - PEERTUBE_SECRET=${PEERTUBE_SECRET}
      - PEERTUBE_ADMIN_EMAIL=${PEERTUBE_ADMIN_EMAIL}
      - PT_INITIAL_ROOT_PASSWORD=${PT_INITIAL_ROOT_PASSWORD}
    volumes:
      - peertube_data:/data
      - peertube_config:/config
    ports:
      - "9000:9000"
      - "1935:1935"
    depends_on:
      - postgres
      - redis
    networks:
      - peertube-network

  postgres:
    image: postgres:16-alpine
    container_name: peertube-db
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=peertube
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - peertube-network

  redis:
    image: redis:7-alpine
    container_name: peertube-redis
    volumes:
      - redis_data:/data
    networks:
      - peertube-network

volumes:
  peertube_data:
  peertube_config:
  postgres_data:
  redis_data:

networks:
  peertube-network:
    driver: bridge
```

## .env

```bash
# PeerTube
POSTGRES_USER=peertube
POSTGRES_PASSWORD=peertube_password
PEERTUBE_HOSTNAME=peertube.example.com
PEERTUBE_SECRET=your-peertube-secret
PEERTUBE_ADMIN_EMAIL=admin@example.com
PT_INITIAL_ROOT_PASSWORD=your_root_password
```

## Usage notes

- Web interface at http://localhost:9000
- Login as root with initial password
- Supports federation with other instances
- Live streaming via RTMP
- Configure hostname for production

## Troubleshooting

- Federation not working with other instances: Verify PEERTUBE_WEBSERVER_HOSTNAME matches your actual domain and SSL certificate is valid
- Video transcoding fails or hangs: Increase Docker memory limits and check PeerTube container logs for ffmpeg errors
- Redis connection errors in PeerTube logs: Ensure redis container is fully started before PeerTube using healthchecks or init containers
- PostgreSQL connection refused: Check that POSTGRES_USER and POSTGRES_PASSWORD environment variables match between postgres and peertube services
- RTMP live streaming not working: Verify port 1935 is open in firewall and not blocked by hosting provider
- High memory usage during video uploads: Configure Redis maxmemory settings and consider enabling PostgreSQL connection pooling

