2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Dockerizing a CouchDB service"
|
|
|
|
description = "Sharing data between 2 couchdb databases"
|
|
|
|
keywords = ["docker, example, package installation, networking, couchdb, data volumes"]
|
|
|
|
[menu.main]
|
2016-01-23 23:36:40 -05:00
|
|
|
parent = "engine_dockerize"
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-04-21 11:50:09 -04:00
|
|
|
# Dockerizing a CouchDB service
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
> **Note**:
|
|
|
|
> - **If you don't like sudo** then see [*Giving non-root
|
|
|
|
> access*](../installation/binaries.md#giving-non-root-access)
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
Here's an example of using data volumes to share the same data between
|
2014-04-15 20:53:12 -04:00
|
|
|
two CouchDB containers. This could be used for hot upgrades, testing
|
|
|
|
different versions of CouchDB on the same data, etc.
|
|
|
|
|
|
|
|
## Create first database
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
Note that we're marking `/var/lib/couchdb` as a data volume.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ COUCH1=$(docker run -d -p 5984 -v /var/lib/couchdb shykes/couchdb:2013-05-03)
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
## Add data to the first database
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
We're assuming your Docker host is reachable at `localhost`. If not,
|
2014-04-17 18:55:24 -04:00
|
|
|
replace `localhost` with the public IP of your Docker host.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-05-01 10:13:34 -04:00
|
|
|
$ HOST=localhost
|
2015-03-26 14:12:37 -04:00
|
|
|
$ URL="http://$HOST:$(docker port $COUCH1 5984 | grep -o '[1-9][0-9]*$')/_utils/"
|
2014-05-01 10:13:34 -04:00
|
|
|
$ echo "Navigate to $URL in your browser, and use the couch interface to add data"
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
## Create second database
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
This time, we're requesting shared access to `$COUCH1`'s volumes.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ COUCH2=$(docker run -d -p 5984 --volumes-from $COUCH1 shykes/couchdb:2013-05-03)
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
## Browse data on the second database
|
|
|
|
|
2014-05-01 10:13:34 -04:00
|
|
|
$ HOST=localhost
|
2015-03-26 14:12:37 -04:00
|
|
|
$ URL="http://$HOST:$(docker port $COUCH2 5984 | grep -o '[1-9][0-9]*$')/_utils/"
|
2014-05-01 10:13:34 -04:00
|
|
|
$ echo "Navigate to $URL in your browser. You should see the same data as in the first database"'!'
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
Congratulations, you are now running two Couchdb containers, completely
|
|
|
|
isolated from each other *except* for their data.
|