Deploy using Docker Compose

You can use Docker compose to deploy a TinyPixel instance

# Prerequisites

  • You have a Linux server available that you can SSH into, possibly using DigitalOcean.
  • You have Docker and Docker Compose installed on that Linux server. It’s suggested that you use official installation instructions from Docker for your distribution.
  • A domain name, or subdomain, with an A record set with your server’s IP.

# Deployment Steps

  1. First, make sure you have a user with UID 1000 set up. You can create one if not:
    adduser --uid 1000 tiny_pixel --disabled-password
    usermod -a -G docker tiny_pixel
    
  2. Next create a docker compose YAML file on your host, typically this file is named compose.yml:
    services:
      caddy:
        image: caddy:2-alpine
        restart: unless-stopped
        ports:
          - "80:80"
          - "443:443"
          - "443:443/udp" # Optional for HTTP/3 support
        volumes:
          - ./Caddyfile:/etc/caddy/Caddyfile
          - caddy_data:/data
          - caddy_config:/config
    
      web:
        image: ghcr.io/mjc-gh/tiny_pixel:0.0.1
        restart: unless-stopped
        environment:
          - TP_DOMAIN_NAME=__REPLACE_WITH_DOMAIN_NAME__
          - RAILS_SECRET_KEY_BASE=${RAILS_SECRET_KEY_BASE}
        volumes:
          - rails-storage:/rails/storage
        depends_on:
          - jobs
    
      jobs:
        image: ghcr.io/mjc-gh/tiny_pixel:0.0.1
        restart: unless-stopped
        command: ./bin/jobs
        environment:
          - TP_DOMAIN_NAME=__REPLACE_WITH_DOMAIN_NAME__
          - RAILS_SECRET_KEY_BASE=${RAILS_SECRET_KEY_BASE}
        volumes:
          - rails-storage:/rails/storage
    
    volumes:
      caddy_data:
      caddy_config:
      rails-storage:
    

    You will need to replace __REPLACE_WITH_DOMAIN_NAME__ with your actual domain name.

    You may need to additional environment variables if you are opting to use Email Delivery and other advanced features. Refer to the configuration page for more details.

  3. Create a Caddyfile in the same directory as your compose.yml. This file configures the reverse proxy:
    __REPLACE_WITH_DOMAIN_NAME__ {
      reverse_proxy web:3000
    }
    

    Replace __REPLACE_WITH_DOMAIN_NAME__ with your actual domain name.

  4. Create a .env file in the same directory as your compose.yml with the required environment variables:
    RAILS_SECRET_KEY_BASE=
    

    For the RAILS_SECRET_KEY_BASE, you need a random value that is sufficiently secure. The simplest way to generate a good secret key is to run:

    openssl rand -hex 64
    

    Copy the output and paste it as the value for RAILS_SECRET_KEY_BASE in your .env file.

  5. Start the Docker Compose services:
    docker compose up -d
    
  6. Once the containers are running, you can reveal your admin URL by running:
    docker exec -it tiny_pixel-web-1 bin/rails tiny_pixel:system_admin_password
    

Within the system admin, you can create a new login for your TinyPixel instance. Once logged in to the application, you can create new sites, configure them, and add teammates.

# Tips

  • Keep your .env file secure: The .env file contains your RAILS_SECRET_KEY_BASE secret. Make sure not to commit it to version control. Consider adding .env to your .gitignore. You can also restrict its permissions with chmod 600 .env.

  • Use block storage for reliable backups: Store your rails-storage volume on a cloud provider’s block storage (like DigitalOcean volumes) to make automated backups and recovery easier.

  • Monitor container logs: Use docker compose logs -f to view live logs from your containers, which is helpful for debugging issues or monitoring the health of your deployment.