Skip to content

Deploying bin

Introduction

bin is a minimal, self-hosted pastebin service that provides a clean and simple way to share code snippets, logs, and text. With no unnecessary features, bin focuses on doing one thing well: storing and sharing text.

Built for speed and simplicity, bin offers syntax highlighting, expiring pastes, and a straightforward API. It’s perfect for developers and teams who want a private paste service without the bloat of larger solutions.

Key highlights of bin:

  • Minimal Design: Clean interface focused on pasting and sharing
  • Syntax Highlighting: Automatic language detection and highlighting
  • Expiring Pastes: Set pastes to expire after a duration
  • Raw View: Access raw text for easy copying
  • API Access: Simple API for programmatic paste creation
  • No Account Required: Anonymous paste creation
  • Burn After Reading: One-time view pastes
  • Private Pastes: Control paste visibility
  • Fast Performance: Lightweight and quick
  • Self-Hosted: Complete control over your data

This guide walks through deploying bin on Klutch.sh using Docker.

Why Deploy bin on Klutch.sh

Deploying bin on Klutch.sh provides several advantages:

Private Sharing: Share sensitive code snippets without third-party access.

HTTPS by Default: Secure paste sharing with automatic SSL.

Always Available: Your paste service runs 24/7.

Simple Deployment: Minimal configuration required.

Custom Domain: Use your own domain for a branded service.

Persistent Storage: Pastes survive container restarts.

Prerequisites

Before deploying bin on Klutch.sh, ensure you have:

Understanding bin Architecture

bin is intentionally simple:

Web Server: Handles paste creation and viewing.

File Storage: Stores pastes as files on disk.

Syntax Highlighter: Provides code highlighting.

Preparing Your Repository

Create a GitHub repository for your bin deployment.

Repository Structure

bin-deploy/
├── Dockerfile
└── .dockerignore

Creating the Dockerfile

Create a Dockerfile for bin:

FROM rust:alpine AS builder
# Install build dependencies
RUN apk add --no-cache musl-dev
# Clone and build bin
WORKDIR /build
RUN apk add --no-cache git \
&& git clone https://github.com/w4/bin.git . \
&& cargo build --release
# Runtime image
FROM alpine:latest
# Install runtime dependencies
RUN apk add --no-cache ca-certificates
# Copy binary
COPY --from=builder /build/target/release/bin /usr/local/bin/bin
# Create directories
WORKDIR /opt/bin
RUN mkdir -p /opt/bin/data
# Environment variables
ENV BIN_LISTEN=0.0.0.0:8080
ENV BIN_DATABASE_PATH=/opt/bin/data
# Expose port
EXPOSE 8080
# Volume for data
VOLUME ["/opt/bin/data"]
# Start bin
CMD ["bin"]

Environment Variables Reference

VariableRequiredDefaultDescription
BIN_LISTENNo0.0.0.0:8080Address and port to listen on
BIN_DATABASE_PATHNo./dataPath to store pastes
BIN_MAX_PASTE_SIZENo1MBMaximum paste size
BIN_ID_LENGTHNo6Length of paste IDs

Deploying bin on Klutch.sh

    Push Your Repository to GitHub

    Initialize and push your configuration to GitHub.

    Create a New Project on Klutch.sh

    Navigate to the Klutch.sh dashboard and create a new project named “bin” or “pastebin”.

    Create a New App

    Within your project, create a new app and connect your GitHub repository.

    Configure HTTP Traffic

    Set up HTTP for the web interface:

    • Select HTTP as the traffic type
    • Set the internal port to 8080

    Attach Persistent Volumes

    Add storage for pastes:

    Mount PathRecommended SizePurpose
    /opt/bin/data5 GBPaste storage

    Deploy Your Application

    Click Deploy to build and start bin.

    Access Your Pastebin

    Once deployment completes, access bin at https://your-app-name.klutch.sh.

Using bin

Creating Pastes

Create a paste through the web interface:

  1. Navigate to your bin URL
  2. Paste or type your content
  3. Click “Save”
  4. Copy the generated URL

Syntax Highlighting

bin automatically detects language, or specify manually:

  1. Add file extension to URL: /paste-id.py
  2. Syntax highlighting applies automatically

Raw View

Access raw paste content:

  1. Add /raw to the URL
  2. View plain text without highlighting

API Usage

Create pastes programmatically:

Terminal window
# Create a paste
curl -X POST https://your-bin.klutch.sh \
-d "Hello, World!"
# Create with expiration
curl -X POST https://your-bin.klutch.sh \
-H "X-Expires: 3600" \
-d "Expires in 1 hour"

Command Line Integration

Add a shell function for easy pasting:

Terminal window
# Add to ~/.bashrc or ~/.zshrc
bin() {
curl -sS -X POST https://your-bin.klutch.sh --data-binary "@${1:--}"
}
# Usage
cat file.txt | bin
bin < script.sh
echo "Hello" | bin

Configuration Options

Expiring Pastes

Configure default expiration:

  • Set X-Expires header with seconds
  • Pastes automatically deleted after expiration

Burn After Reading

Create one-time pastes:

  • Set X-Burn header to true
  • Paste deleted after first view

Maximum Size

Control paste size limits:

  • Set BIN_MAX_PASTE_SIZE environment variable
  • Rejects pastes exceeding limit

Troubleshooting Common Issues

Paste Not Saving

Solutions:

  • Check paste size is within limits
  • Verify storage volume is mounted
  • Review server logs for errors

Syntax Highlighting Not Working

Solutions:

  • Verify file extension is recognized
  • Try specifying language explicitly
  • Check JavaScript is enabled in browser

404 on Paste Access

Solutions:

  • Verify paste ID is correct
  • Check if paste has expired
  • Confirm paste was successfully created

Additional Resources

Conclusion

Deploying bin on Klutch.sh gives you a minimal, fast pastebin service for sharing code and text. With syntax highlighting, expiring pastes, and a simple API, bin provides everything you need for quick text sharing without the complexity of larger solutions.