# Hastebin Pastebin

> Simple pastebin alternative for sharing code snippets.

- Category: Productivity & Collaboration
- Difficulty: beginner
- Components: hastebin, redis
- Tags: pastebin, hastebin, code-sharing, snippets
- Source: https://docker.recipes/productivity/hastebin-pastebin

## Overview

Hastebin is a minimalist, open-source pastebin service originally created by John Crepezzi that focuses on speed and simplicity for sharing code snippets and text. Unlike traditional pastebins that require forms and captchas, Hastebin provides an elegant interface where users can paste content directly and immediately receive a shareable URL, making it ideal for quick code sharing during development or debugging sessions. This implementation uses Redis as the backend storage engine, providing fast in-memory data access and built-in expiration capabilities that automatically clean up old pastes after 30 days. The combination of Haste Server and Redis creates a high-performance pastebin solution that can handle thousands of paste operations per second while maintaining data persistence through Redis's RDB snapshots. This stack is perfect for development teams, educational institutions, and organizations that need a private, self-hosted alternative to public pastebin services with complete control over data retention and access policies.

## Features

- Lightning-fast paste creation with immediate URL generation via Haste Server's streamlined interface
- Automatic syntax highlighting for 150+ programming languages including JavaScript, Python, Go, and Rust
- Built-in keyboard shortcuts (Ctrl+S to save, Ctrl+N for new paste) for rapid workflow integration
- Redis-powered automatic paste expiration after 30 days to prevent storage bloat
- RESTful API support for programmatic paste creation and retrieval
- Command-line integration allowing direct piping of files and command output
- Raw text viewing mode for easy copy-paste operations without formatting
- Duplicate paste detection through Redis key management to optimize storage

## Use cases

- Development teams sharing code snippets during pair programming and code reviews
- Educational environments where instructors need to quickly share code examples with students
- Internal corporate pastebin for sharing configuration files and scripts without external dependencies
- DevOps teams sharing deployment scripts and configuration snippets during incident response
- Open source projects providing a branded pastebin for community code sharing
- Homelab enthusiasts running a personal pastebin for cross-device text and code synchronization
- Organizations requiring GDPR compliance with full control over paste data storage and retention

## Prerequisites

- Docker and Docker Compose installed with at least 1GB available RAM for Redis operations
- Port 7777 available for the Haste Server web interface and API access
- Basic understanding of Redis data structures for troubleshooting storage issues
- Approximately 512MB RAM allocated for Redis to handle concurrent paste operations effectively
- Network access configured if planning to use the CLI haste-client tool from remote machines
- Understanding of paste expiration policies to communicate data retention to users

## docker-compose.yml

```yaml
services:
  hastebin:
    image: ghcr.io/toptal/haste-server:latest
    container_name: hastebin
    environment:
      - STORAGE_TYPE=redis
      - STORAGE_HOST=redis
      - STORAGE_PORT=6379
      - STORAGE_EXPIRE_SECONDS=2592000
    ports:
      - "7777:7777"
    depends_on:
      - redis
    networks:
      - hastebin-network
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    container_name: hastebin-redis
    volumes:
      - redis-data:/data
    networks:
      - hastebin-network
    restart: unless-stopped

volumes:
  redis-data:

networks:
  hastebin-network:
    driver: bridge
```

## .env

```bash
# Hastebin
# Default expiration: 30 days
```

## Usage notes

- Web UI at http://localhost:7777
- Paste code and get shareable link
- Keyboard shortcuts available
- Syntax highlighting
- CLI tool: cat file | haste

## Troubleshooting

- Pastes not saving or returning 500 errors: Check Redis container logs for memory issues and ensure STORAGE_HOST environment variable matches the Redis service name
- Syntax highlighting not working for specific languages: Verify the paste content has proper file extensions or language hints, as Haste Server relies on content analysis for highlighting
- CLI haste command timing out: Ensure the haste-client is configured with the correct server URL and that port 7777 is accessible from the client machine
- Redis data persistence lost after container restart: Verify the redis-data volume is properly mounted and Redis has write permissions to /data directory
- High memory usage in Redis container: Monitor paste creation rate and consider reducing STORAGE_EXPIRE_SECONDS or implementing Redis maxmemory policies for automatic eviction
- Pastes expiring too quickly or not expiring: Verify STORAGE_EXPIRE_SECONDS is set correctly (2592000 = 30 days) and Redis is processing TTL commands properly

