2014-04-15 20:53:12 -04:00
|
|
|
page_title: Sharing data between 2 couchdb databases
|
|
|
|
page_description: Sharing data between 2 couchdb databases
|
|
|
|
page_keywords: docker, example, package installation, networking, couchdb, data volumes
|
|
|
|
|
|
|
|
# CouchDB Service
|
|
|
|
|
2014-04-18 16:21:55 -04:00
|
|
|
> **Note**:
|
|
|
|
>
|
|
|
|
> - This example assumes you have Docker running in daemon mode. For
|
|
|
|
> more information please see [*Check your Docker
|
|
|
|
> install*](../hello_world/#running-examples).
|
2014-04-23 16:48:28 -04:00
|
|
|
> - **If you don't like sudo** then see [*Giving non-root
|
2014-04-24 08:12:21 -04:00
|
|
|
> access*](/installation/binaries/#dockergroup)
|
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
|
|
|
|
2014-05-01 10:13:34 -04:00
|
|
|
$ COUCH1=$(sudo 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
|
2014-05-18 02:16:23 -04:00
|
|
|
$ URL="http://$HOST:$(sudo 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
|
|
|
|
2014-05-01 10:13:34 -04:00
|
|
|
$ COUCH2=$(sudo 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
|
2014-05-18 02:16:23 -04:00
|
|
|
$ URL="http://$HOST:$(sudo 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.
|