#!/bin/sh

# bind port 5984 to localhost in order to be able to ssh tunnel into couchdb futon admin web interface.
docker run -d --name couchdb --restart=always -v /data/couchdb:/usr/local/var/lib/couchdb -p 127.0.0.1:5984:5984 klaemo/couchdb:1.6.1

# Sleep for 1sec to let couchdb container start up
sleep 1

docker run -it --rm --link couchdb:couchdb yxdhde/alpine-curl-git curl -X PUT couchdb:5984/_config/admins/admin -d '"secret"'

docker run -it --rm --link couchdb:couchdb yxdhde/alpine-curl-git curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' couchdb:5984/_session -d 'name=admin&password=secret'