Containerize Ditto with Docker
326
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:
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.
db as defined in the compose file.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.
Next, pull the pre-built Docker images:
docker compose pull
Run this command to create the Postgres database:
docker compose up -d db
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.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:
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:
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:
mkdir -p ditto/public
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:
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.
Content type
Image
Digest
sha256:8b8b24e2b…
Size
126.3 MB
Last updated
over 1 year ago
docker pull openmtx/ditto