Sign inSign up

openmtx/ditto

By openmtx

•Updated over 1 year ago

Containerize Ditto with Docker

Image
Networking
Web servers
0

326

openmtx/ditto repository overview

⁠Containerize Ditto with Docker

Ditto, another social network application, comes from Alex Gleason⁠, who previously created the Soapbox⁠ frontend for Masterdon⁠ and Rebase⁠ Fediverse backends, the Mostr⁠ bridge between Masterdon and Nostr⁠ networks.

This guide helps you deploy your own Ditto service quickly using Docker. We'll assume your domain for the instance is ditto.great.domain.

Backend: We'll use PostgresSQL⁠ as the backend for Ditto.

Basic Docker Compose File:

services:
  ditto:
    image: openmtx/ditto:latest
    container_name: ditto
    init: true
    restart: always
    volumes:
      #- ./ditto-env:/app/.env
      - ./ditto/public:/app/public
    depends_on:
      - db

  db:
    image: postgres:17
    container_name: postgres
    restart: always
    volumes:
      - ./db/data:/var/lib/postgresql/data
    env_file:
      - ./db-env

  nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    volumes:
      - ./nginx/ditto.conf:/etc/nginx/conf.d/ditto.conf:ro
      - ./ditto/public:/var/www/ditto/public
    ports:
      - "127.0.0.1:8080:80"
    depends_on:
      - ditto

Explanation:

  • We define three services: ditto, db (database), and nginx (reverse proxy).
  • ditto uses the openmtx/ditto:latest image and mounts the local ditto/public directory for keeping soapbox code.
  • db uses the postgres:17 image and stores data in the mounted db/data directory.
  • nginx uses the nginx:latest image, serves the application using the ditto.conf configuration file, and mounts the ditto/public directory for static content.

Reverse Proxy:

A basic nginx reverse proxy sits in front of the ditto service, listening on port 8080 of localhost. You can easily add another reverse proxy like nginx, caddy or traefik with SSL for external access.

⁠Setting Up Database Parameters

  • The database hostname is db as defined in the compose file.
  • Modify the database name, username, and password in the db-env file. These will be used to set up the DATABASE_URL parameter in ditto.

Content of db-env:

POSTGRES_DB=ditto
POSTGRES_USER=ditto
POSTGRES_PASSWORD=StrongPass

Remember to replace StrongPass with a strong password.

⁠Pulling Images

Next, pull the pre-built Docker images:

docker compose pull

⁠Provisioning the Database

Run this command to create the Postgres database:

docker compose up -d db

⁠Setting Up Ditto Parameters

  • Ditto parameters are defined in the ditto-env file, mounted as /app/.env inside the container. It's commented out for now. Once the parameter is set, please uncomment the volume mount.
  • To generate the parameters, run init_ditto from the ditto container:
docker compose run --rm ditto init_ditto

Follow the prompts to generate the .env file. Copy the lines between the --- markers and save them as ditto-env.

Example ditto-env content:

DITTO_NSEC="..."  # Replace with generated key
LOCAL_DOMAIN="https://ditto.great.domain:4036"
DATABASE_URL="postgres://ditto:StrongPass@db:5432/ditto"
DITTO_UPLOADER="nostrbuild"
NOSTRBUILD_ENDPOINT="https://nostr.build/api/v2/upload/files"
VAPID_PRIVATE_KEY="..."  # Replace with generated key

Important:

  • Replace ditto.great.domain with your actual domain name.

Uncomment the volume mount for `/app.env', the current compose file should be like this:

services:
  ditto:
    image: openmtx/ditto:latest
    container_name: ditto
    init: true
    restart: always
    volumes:
      - ./ditto-env:/app/.env
      - ./ditto/public:/app/public
    depends_on:
      - db

  db:
    image: postgres:17
    container_name: postgres
    restart: always
    volumes:
      - ./db/data:/var/lib/postgresql/data
    env_file:
      - ./db-env

  nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    volumes:
      - ./nginx/ditto.conf:/etc/nginx/conf.d/ditto.conf:ro
      - ./ditto/public:/var/www/ditto/public
    ports:
      - "127.0.0.1:8080:80"
    depends_on:
      - ditto

Setting Up Nginx Parameters:

Modify the server name in nginx/ditto.conf to your actual domain name:

server {
  listen 80;
  listen [::]:80;

  server_name your_domain_name;  # Replace with your domain

  keepalive_timeout 70;
  sendfile on;
  client_max_body_size 100m;
  ignore_invalid_headers off;
}

Here's a reworded version of the markdown paragraphs:

⁠Running the Ditto Container Service

The ditto container will automatically fetch the latest version of soapbox and store it in the /app/public directory. Since this directory is a mounted volume, you'll need to ensure the host directory has the correct permissions for the ditto container to write to it.

Prepare the Local Directory:

  1. Create the directory:
    mkdir -p ditto/public
    
  2. Set appropriate permissions:
    chmod a+rw ditto/public 
    

Start the Ditto Service:

Use the following command to start the ditto container in detached mode:

docker compose up -d

Test the Service:

Verify the service is running correctly by sending a curl request:

curl --header 'Host: ditto.great.domain' http://localhost:8080 

If the response contains HTML, including the soapbox element and a message about enabling JavaScript, the setup is successful.

Here's a reworded version of the MD paragraphs:

⁠Setting Up the Admin User

To designate Jack Dorsey as the system administrator, we will use his public key:

npub1sg6plzptd64u62a878hep2kev88swjh3tw00gjsfl8f237lmu63q0uf63m

The following command will grant Jack Dorsey the system administrator privilege on this system:

docker compose run --rm ditto promote_user npub1sg6plzptd64u62a878hep2kev88swjh3tw00gjsfl8f237lmu63q0uf63m

Following the execution of this command, Jack Dorsey will have system administrator permissions.

Tag summary

Content type

Image

Digest

sha256:8b8b24e2b…

Size

126.3 MB

Last updated

over 1 year ago

docker pull openmtx/ditto