CouchDB is an open-source NoSQL document database that stores data as JSON, exposes a full RESTful HTTP API, and replicates between nodes natively. This guide deploys CouchDB using Docker Compose with Traefik handling automatic HTTPS, then verifies it with a database and document round-trip. By the end, you'll have CouchDB serving JSON documents over HTTPS at your domain.
Set Up the Directory Structure
1. Create the project directory structure:
$ mkdir -p ~/couchdb-logging/couchdb-data
$ cd ~/couchdb-logging
2. Set ownership for the CouchDB data directory:
$ sudo chown -R 5984:5984 couchdb-data
3. Create the environment file:
$ nano .env
DOMAIN=couchdb.example.com
LETSENCRYPT_EMAIL=admin@example.com
COUCHDB_USER=admin
COUCHDB_PASSWORD=changeme
Deploy with Docker Compose
1. Create the Docker Compose manifest:
$ nano docker-compose.yaml
services:
traefik:
image: traefik:v3.6
container_name: traefik
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--certificatesresolvers.letsencrypt.acme.httpchallenge=true"
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
- "--certificatesresolvers.letsencrypt.acme.email=${LETSENCRYPT_EMAIL}"
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- "letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
restart: unless-stopped
couchdb:
image: couchdb:latest
container_name: couchdb
hostname: couchdb
expose:
- "5984"
volumes:
- "./couchdb-data:/opt/couchdb/data"
environment:
- COUCHDB_USER=${COUCHDB_USER}
- COUCHDB_PASSWORD=${COUCHDB_PASSWORD}
labels:
- "traefik.enable=true"
- "traefik.http.routers.couchdb.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.couchdb.entrypoints=websecure"
- "traefik.http.routers.couchdb.tls.certresolver=letsencrypt"
- "traefik.http.services.couchdb.loadbalancer.server.port=5984"
restart: unless-stopped
volumes:
letsencrypt:
2. Start the services:
$ docker compose up -d
3. Verify the services are running:
$ docker compose ps
$ docker compose logs
Access CouchDB
1. Create a database:
$ curl -X PUT https://admin:changeme@couchdb.example.com/logs
2. Insert a document:
$ curl -X POST https://admin:changeme@couchdb.example.com/logs \
-H "Content-Type: application/json" \
-d '{"level":"info","message":"first entry"}'
3. List all documents:
$ curl https://admin:changeme@couchdb.example.com/logs/_all_docs
The built-in admin UI (Fauxton) is available at https://couchdb.example.com/_utils/.
Next Steps
CouchDB is running and serving JSON documents over HTTPS. From here you can:
- Create design documents with map/reduce views for structured queries
- Set up continuous replication between CouchDB nodes or to PouchDB clients
- Add per-database security objects to scope read/write access
For the full guide with additional tips, visit the original article on Vultr Docs.
Top comments (0)