Docker + CouchDB optimal configuration for continuous deployment

2

2

I have recently started to experiment with Docker and when it comes to code deployments (i.e. node server) it works extremely well. However when it comes to deployment of a couchDB server it poses a challenge. The challenging aspect is probably related to my ignorance on the topic.

The current setup: Continuous deployment to AWS EC2 instance
The Issue: Every deployment wipes the database and reinstalls couchDB
End goal: Deployments should not remove and reinstall the database. They should simply update the couchdb configuration if one is provided (i.e. turn off admin party mode, add user, ...)

Dockerfile: Pretty simple: FROM couchdb:latest

What are some approaches I can use to accomplish this?

dipole_moment

Posted 2016-07-17T04:25:34.140

Reputation: 121

The more I think about it I am not entirely sure I should be using Docker for database deployment. Rather, I should use it as a one-time-setup. – dipole_moment – 2016-07-17T04:26:34.233

Hey if you check @werty1st's response you can see that deploying configured CouchDB instances is supported so long as you use a separate container for persistent data or write the data to a host directory outside the container. – Ilias Karim – 2018-08-09T04:00:25.463

Answers

2

You have to make your Data Volume persistent.

1. Option:

Mount Host Directory into the container

docker run -rm -p 5984:5984 -v /srv/db_files:/usr/local/var/lib/couchdb --name couchdb klaemo/couchdb:1.6.1

2. Option:

A Datastore container (which doesn't reset after recreateing the couchdb container)

Create Datastore

docker create -v /usr/local/var/lib/couchdb --name datastore busybox:latest /bin/true

(it's also possible to mount a host dir into the datastore container)

docker create -v /srv/db_files:/usr/local/var/lib/couchdb --name datastore busybox:latest /bin/true

Use Datastore

docker run -d --volumes-from datastore -p 5984:5984 --name db1 klaemo/couchdb bash

werty1st

Posted 2016-07-17T04:25:34.140

Reputation: 41

If you want to maintain the configuration its explained here: https://hub.docker.com/_/couchdb/ -> Using your own CouchDB configuration file

– werty1st – 2017-02-28T14:49:20.613

These sound like great suggestions. I wonder are these solutions compatible with ECS clusters or only with EC2 instances? – Ilias Karim – 2018-08-09T04:18:01.217

1

I think the best way to configure CouchDB without wiping out the whole server, is running a script with curl.

For instance, you can enable CORS with the following script (I am using Windows and the escaping is different from UNIX) so I created a BAT file with the following:

set host=%1
echo %host%

if [%host%] == [] (
    SET host=http://localhost:32770
)

curl -X PUT %host%/_config/httpd/enable_cors -d "\"true\""
curl -X PUT %host%/_config/cors/origins -d "\"*\""
curl -X PUT %host%/_config/cors/credentials -d "\"true\""
curl -X PUT %host%/_config/cors/methods -d "\""GET, PUT, POST, HEAD, DELETE\""
curl -X PUT %host%/_config/cors/headers -d "\"accept, authorization, content-type, origin, referer, x-csrf-token\""
curl -X PUT %host%/mydb

NodeJS has a plugin which does the same CORS configuration for you: https://github.com/pouchdb/add-cors-to-couchdb.

Using curl you can change all the configurations you want, including creating databases, users and records.

pfernandom

Posted 2016-07-17T04:25:34.140

Reputation: 111