Self-Hosting Firefox Sync with Docker

🧭 You move the storage, not the account

Your Mozilla account stays where it is. Only the place where the encrypted data is stored changes.

This is the part that confuses people, so it comes first. Firefox Sync is two services:

ServiceWhat it doesWhere it lives after this guide
Mozilla accountsLogin, password, device listStill at Mozilla
Token serverTells the browser which storage node to useYour server
Sync storageHolds the synced recordsYour server

You keep signing in with the same account. The browser then asks your token server where to put the data, and gets your storage node as the answer.

Two consequences worth knowing before you start:

  • The server never sees your data. Records are encrypted in the browser with a key derived from your account. What lands in the database is ciphertext - you will see it with your own eyes below.
  • There is no web interface. A sync server is used by Firefox, not by people.

πŸ“¦ What you need

  • A Linux host with Docker and Docker Compose
  • A Mozilla account
  • For anything beyond a local trial: a domain name and a reverse proxy with HTTPS

A year ago this meant compiling a Rust project from source. Today Mozilla publishes ready-made images on ghcr.io, one per database backend. This guide uses the MySQL one.

πŸ—οΈ The stack

Three files in one directory.

docker-compose.yml

services:
  syncstorage_mysql:
    image: mysql:8.0
    container_name: firefox-sync-mysql
    restart: unless-stopped
    command: --explicit_defaults_for_timestamp
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_USER: "${MYSQL_USER}"
      MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
      TZ: UTC
    volumes:
      - ./mysql_data:/var/lib/mysql
      - ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
    networks:
      - sync-net
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USER -p$$MYSQL_PASSWORD"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 60s

  syncstorage_app:
    image: ghcr.io/mozilla-services/syncstorage-rs/syncserver-mysql:${SYNCSERVER_VERSION:-0.24.1}
    platform: linux/amd64
    container_name: firefox-syncstorage-rs
    restart: unless-stopped
    ports:
      - "${SYNC_BIND:-127.0.0.1:8000}:8000"
    environment:
      SYNC_HOST: "0.0.0.0"
      SYNC_PORT: "8000"
      SYNC_MASTER_SECRET: "${MASTER_SECRET}"
      SYNC_HUMAN_LOGS: "true"
      SYNC_SYNCSTORAGE__DATABASE_URL: "mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@syncstorage_mysql:3306/syncstorage_rs"
      SYNC_TOKENSERVER__DATABASE_URL: "mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@syncstorage_mysql:3306/tokenserver_rs"
      SYNC_TOKENSERVER__ENABLED: "true"
      SYNC_TOKENSERVER__NODE_TYPE: "mysql"
      SYNC_TOKENSERVER__RUN_MIGRATIONS: "true"
      SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: "api.accounts.firefox.com"
      SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL: "https://oauth.accounts.firefox.com"
      SYNC_TOKENSERVER__FXA_METRICS_HASH_SECRET: "${FXA_METRICS_SECRET}"
      SYNC_TOKENSERVER__INIT_NODE_URL: "${PUBLIC_URL}"
      SYNC_TOKENSERVER__ALLOW_NEW_USERS: "${ALLOW_NEW_USERS:-true}"
    depends_on:
      syncstorage_mysql:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/__heartbeat__"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    networks:
      - sync-net

networks:
  sync-net:
    driver: bridge

What the less obvious lines do:

SettingWhy it is there
SYNC_TOKENSERVER__RUN_MIGRATIONSCreates the token server tables at startup. The storage tables are always created
SYNC_TOKENSERVER__INIT_NODE_URLRegisters your server as the storage node. Written once, on first start
SYNC_TOKENSERVER__FXA_*Points at Mozilla’s production account servers, to validate logins
SYNC_TOKENSERVER__ALLOW_NEW_USERSWhether accounts never seen before may use the server. See the lock-down section
SYNC_BINDThe port is published on 127.0.0.1 only, unless you say otherwise

init-db.sh

One MySQL instance, two databases. The script runs once, the first time MySQL starts on an empty data directory.

#!/bin/bash
set -e

mysql -u root -p"${MYSQL_ROOT_PASSWORD}" <<SQL
CREATE DATABASE IF NOT EXISTS syncstorage_rs;
CREATE DATABASE IF NOT EXISTS tokenserver_rs;
GRANT ALL PRIVILEGES ON syncstorage_rs.* TO '${MYSQL_USER}'@'%';
GRANT ALL PRIVILEGES ON tokenserver_rs.* TO '${MYSQL_USER}'@'%';
FLUSH PRIVILEGES;
SQL
chmod +x init-db.sh

.env

MYSQL_ROOT_PASSWORD=...
MYSQL_USER=syncuser
MYSQL_PASSWORD=...
MASTER_SECRET=...
FXA_METRICS_SECRET=...

# Protocol + host, no path. For a first local trial:
PUBLIC_URL=http://localhost:8000

Generate the four secrets like this:

echo "MYSQL_ROOT_PASSWORD=$(openssl rand -hex 16)"
echo "MYSQL_PASSWORD=$(openssl rand -hex 16)"
echo "MASTER_SECRET=$(openssl rand -hex 32)"
echo "FXA_METRICS_SECRET=$(openssl rand -hex 32)"
chmod 600 .env

▢️ Start it and check it

docker compose up -d
docker compose ps

Both containers should reach healthy within a minute. Then:

curl http://localhost:8000/__heartbeat__
{"status":"Ok","database":"Ok","version":"0.24.1","quota":{"enabled":false,"size":2097152000}}
The heartbeat endpoint opened in Firefox
/__heartbeat__ is the only page worth opening in a browser

Two more answers that look like failures and are not:

You openYou getMeaning
/A redirect to Mozilla’s API documentationNormal. There is no home page
/1.0/sync/1.5401 UnauthorizedNormal. It wants the credentials only Firefox sends

🦊 Point Firefox at it

One preference. Open about:config and search for identity.sync.tokenserver.uri:

The default token server in about:config
The default: Mozilla’s token server

Change it to your server, keeping the /1.0/sync/1.5 path:

http://localhost:8000/1.0/sync/1.5

or, once the server is public:

https://sync.example.com/1.0/sync/1.5
The token server changed to a custom URL
Bold means modified. The arrow on the right puts the default back

Restart Firefox, then sign in as usual from Settings β†’ Account and sync:

The Account and sync page before signing in
The sign-in is still Mozilla’s. Only what happens afterwards changes

The first sync starts by itself as soon as you are in.

πŸͺ€ The trap: “Sync now” that only syncs tabs

This one cost me twenty minutes of staring at a database.

I saved a password, clicked the account icon in the toolbar, saw “Last synced: 1 second ago”, and looked on the server: no passwords. Again. Still nothing.

The sync log (about:sync-log) had the answer in one line:

Sync.Synchronizer   INFO   Syncing specified engines: ["tabs"]

Opening the account panel triggers a quick sync of the open tabs only. It says “synced”, and it is true - for tabs. Everything else waits for the next scheduled full sync, which can be an hour away.

To force a real, full sync:

Settings β†’ Account and sync β†’ Sync β†’ Sync Now

After that button, the log shows every engine, and the password is on the server.

πŸ”Ž See it on the server

Which accounts are registered:

docker compose exec syncstorage_mysql sh -c \
  'mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "SELECT uid, nodeid FROM tokenserver_rs.users"'

What has been stored, by collection:

docker compose exec syncstorage_mysql sh -c 'mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "
SELECT c.name AS collection, COUNT(*) AS records
FROM syncstorage_rs.bso b
LEFT JOIN syncstorage_rs.collections c ON c.id = b.collection
GROUP BY 1 ORDER BY 2 DESC"'
collection   records
bookmarks    9
history      7
forms        3
passwords    1
tabs         1
...

And what a password looks like from the server’s point of view:

docker compose exec syncstorage_mysql sh -c 'mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "
SELECT LEFT(b.payload, 45) AS payload
FROM syncstorage_rs.bso b
JOIN syncstorage_rs.collections c ON c.id = b.collection
WHERE c.name = \"passwords\""'
{"ciphertext":"T1vbcR3mnM7HAzdLMunw+Fm5CONOdE...

No site, no username, no password. That is all your server ever holds.

The test that actually proves it

Uploading is half the story. To know the data can come back:

1. profile A: save a password, Settings β†’ Sync Now
2. check the server: the passwords collection exists
3. profile B (brand new, same tokenserver preference): sign in
4. about:logins on profile B shows the password

On the server side, step 3 shows up as a plain GET /storage/passwords - no delete, no upload. The new browser asked, and the server answered.

🌍 Going public

To sync a phone, or a laptop away from home, the server needs a public HTTPS address.

1. Set the real URL before the first start. On the production host, in .env:

PUBLIC_URL=https://sync.example.com
SYNC_BIND=0.0.0.0:8000     # only if the reverse proxy is on another machine

2. Put a reverse proxy in front. Any will do. The nginx version:

server {
    listen 443 ssl;
    server_name sync.example.com;

    ssl_certificate     /etc/letsencrypt/live/sync.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/sync.example.com/privkey.pem;

    client_max_body_size 100m;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. Check it from outside your network, not from the server itself:

curl https://sync.example.com/__heartbeat__

4. Change the preference in every browser to https://sync.example.com/1.0/sync/1.5.

πŸ”’ Lock the door behind you

A public sync server accepts any Mozilla account by default. Whoever learns the URL can use your disk as their storage. They cannot read your data - but it is your disk.

Once every account of yours has signed in at least once:

# .env
ALLOW_NEW_USERS=false
docker compose up -d

From then on only accounts already in tokenserver_rs.users are served. To let a new account in, switch it back to true, sign in, switch it off again.

πŸ“± Firefox for Android

There is no about:config on the release version, but there is a hidden menu:

1. Settings β†’ About Firefox
2. Tap the Firefox logo until the debug menu is enabled
3. Back in Settings: Sync Debug
4. Custom Sync server β†’ https://sync.example.com/1.0/sync/1.5
5. Tap "Stop Firefox" in the same menu, then reopen it and sign in

The simplest order is to set it before signing in.

πŸ”§ Day-to-day

# Logs
docker compose logs -f syncstorage_app

# Update: change SYNCSERVER_VERSION in .env, then
docker compose pull && docker compose up -d

# Backup
docker compose exec -T syncstorage_mysql sh -c \
  'mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD --databases syncstorage_rs tokenserver_rs' \
  > sync-backup-$(date +%F).sql

Pin the version. latest on a service that holds your passwords is a surprise waiting for a Tuesday.

↩️ Going back

Reset identity.sync.tokenserver.uri (the arrow in about:config), restart Firefox, and the browser talks to Mozilla’s servers again, where your data is exactly as you left it.

πŸͺ€ Traps, in one table

SymptomCause
“Synced 1 second ago” but nothing on the serverThe toolbar panel syncs tabs only. Use Sync Now in Settings
The server URL opens Mozilla’s documentationNormal: / redirects there
401 on /1.0/sync/1.5 in a browserNormal: only Firefox carries the credentials
The app cannot connect to the databaseCheck the password for / or +: it sits inside a URL. Use hex
Changed PUBLIC_URL, browsers still use the old oneThe node is stored in tokenserver_rs.nodes at first start
init-db.sh did nothingIt only runs on an empty mysql_data/
Strangers in tokenserver_rs.usersALLOW_NEW_USERS left at true on a public server

πŸ“š References