Sync little subsets of your Postgres data into local apps and services.
1.3K
⚠️ This is not an official page for the Electric sync service. You're looking for https://hub.docker.com/r/electricsql/electric
Electric is an open-source Postgres sync engine. It reads changes from Postgres over logical replication and syncs subsets of your data, called shapes, into local apps and services. Each client subscribes only to the rows it needs (partial replication), and Electric keeps them up to date in real time. Data goes out over plain HTTP, so standard caching proxies and CDNs can fan it out to very large numbers of clients.
Source code: https://github.com/electric-sql/electric
Save this as docker-compose.yaml. It runs Postgres with logical replication turned on, plus Electric, for local development:
services:
postgres:
image: postgres:17-alpine
environment:
POSTGRES_DB: electric
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
command: ["postgres", "-c", "wal_level=logical"]
ports:
- "54321:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
electric:
image: electricsql/electric
environment:
DATABASE_URL: postgresql://postgres:password@postgres:5432/electric?sslmode=disable
ELECTRIC_INSECURE: "true" # local development only
ports:
- "3000:3000"
depends_on:
postgres:
condition: service_healthy
⚠️
ELECTRIC_INSECURE=trueturns off API authentication. Use it for local development only. Anyone who can reach the port can read any data the database user can read.
Start it, create a table, and sync it:
docker compose up -d
docker compose exec postgres psql -U postgres -d electric \
-c "CREATE TABLE items (id serial PRIMARY KEY, name text); INSERT INTO items (name) VALUES ('hello'), ('world');"
curl http://localhost:3000/v1/health
curl "http://localhost:3000/v1/shape?table=items&offset=-1"
Using your own Postgres? Point DATABASE_URL at it instead. It must have wal_level = logical, and the user needs the REPLICATION attribute. If Postgres runs on the same machine as Docker, use host.docker.internal as the hostname. On Linux without Docker Desktop, that name only exists if you add --add-host=host.docker.internal:host-gateway (or extra_hosts: ["host.docker.internal:host-gateway"] in Compose). Postgres must also listen on the Docker bridge interface (listen_addresses) and allow that subnet in pg_hba.conf.
Full walkthrough: Quickstart
For any deployment beyond your laptop, set ELECTRIC_SECRET and put Electric's storage on a volume:
docker volume create electric_data
docker run -d --name electric --restart unless-stopped -p 3000:3000 \
-e DATABASE_URL="postgresql://electric:[email protected]:5432/mydb" \
-e ELECTRIC_SECRET="<long random string>" \
-e ELECTRIC_STORAGE_DIR=/var/lib/electric \
-v electric_data:/var/lib/electric \
electricsql/electric:1.8.1
?secret=<ELECTRIC_SECRET>. Add it in your backend or authorizing proxy; never send it from browsers or apps.Electric is configured with environment variables. The most important ones:
| Variable | Default | Purpose |
|---|---|---|
DATABASE_URL | — (required) | Postgres connection string. The role needs the REPLICATION attribute. |
ELECTRIC_SECRET | — (required*) | API secret that shape requests must include. |
ELECTRIC_INSECURE | false | Set to true to run without a secret. Local development only. |
ELECTRIC_STORAGE_DIR | ./persistent (/app/persistent) | Where shape data is stored on disk. Mount a persistent volume here. |
ELECTRIC_PORT | 3000 | HTTP port. |
ELECTRIC_POOLED_DATABASE_URL | DATABASE_URL | Optional pooled connection for non-replication queries. |
ELECTRIC_LOG_LEVEL | info | error, warning, info or debug. |
* Required unless ELECTRIC_INSECURE=true.
All options: Configuration reference
wal_level = logical).REPLICATION attribute (permissions guide).ELECTRIC_STORAGE_DIR, ideally fast local SSD.ELECTRIC_SECRET and put an authorizing proxy in front of Electric (security guide).GET /v1/health needs no authentication and suits liveness and readiness probes. The image has a built-in HEALTHCHECK.Full guide: Deployment
| Tag | What it is |
|---|---|
latest | The current stable release. |
X.Y.Z (e.g. 1.8.1) | A pinned stable release. Recommended for production, so you control when you upgrade. |
canary | Built from main on every merge. For testing unreleased changes; not for production. |
Images are published for linux/amd64 and linux/arm64. Release notes: GitHub Releases. Before upgrading, read the upgrading guide.
Apache-2.0. See LICENSE.
Content type
Image
Digest
sha256:4226bc514…
Size
58.2 MB
Last updated
2 months ago
docker pull alco/electric