Best Practices for Virtualized Platforms provide best practices for running Couchbase on a virtualized platform like Amazon Web Services and Azure. In addition, it also provide some recommendations for running it as Docker container.
One of the recommendations is to map Couchbase node specific data to a local folder. Let’s understand that in more detail.
Implicit Per-Container Storage
If a Couchbase container is started as:
1
2
3
|
docker run -d -p 8091-8093:8091-8093 -p 11210:11210 --name db couchbase/server:sandbox
|
This container:
- Starts in a detached mode using
-d
- Different query, caching and administration ports are mapped using
-p
- A name is provided using
--name
- Image is
couchbase/server:sandbox
By default, the data for the container is stored in a managed volume. Checking volume mounts using the docker inspect
command shows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
docker inspect --format '{{json .Mounts }}' db | jq
[
{
"Name": "aa3c06f9c506d52bfb5d3d265f7b63045df0fea996998f12ce08b2543345e948",
"Source": "/var/lib/docker/volumes/aa3c06f9c506d52bfb5d3d265f7b63045df0fea996998f12ce08b2543345e948/_data",
"Destination": "/opt/couchbase/var",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
]
|
The data for Couchbase is stored in the container filesystem defined by the value of Source
attribute. This can be verified by logging into the root filesystem:
1
2
3
|
docker run -it --pid=host --privileged debian:jessie nsenter -t 1 -m -p -n
|
Now you can see the data directory:
1
2
3
4
|
010e52853bc6:~# ls /var/lib/docker/volumes | grep aa3c
aa3c06f9c506d52bfb5d3d265f7b63045df0fea996998f12ce08b2543345e948
|
A new directory is created for a new run of the container. This directory is still around when the container is stopped and removed but no longer easily accessible. Thus no data is preserved across container restarts.
The volume can be explicitly removed, along with container, using the command:
1
2
3
|
docker rm -v db
|
If the container terminates then the entire state of the application is lost.
Explicit Host Directory Mapping
Now, let’s start a Couchbase container with explicit volume mapping:
1
2
3
|
docker run -d -p 8091-8093:8091-8093 -p 11210:11210 --name db -v ~/couchbase:/opt/couchbase/var couchbase/server:sandbox
|
This container is very similar to the container started earlier. The main difference is that a directory from host ~/couchbase
is mapped to a directory in the container /opt/couchbase/var
.
Couchbase container persists any data in /opt/couchbase/var
directory in the container filesystem. Now that directory is mapped to a directory on the host filesystem. This allows to persist state of the container outside on the host filesystem. The bypasses the union filesystem used by Docker and exposes the host filesystem to the container. This allows the state to persist across container restarts. The new container only needs to start with the exact same volume mapping.
More details about the container can be seen as:
1
2
3
|
docker inspect --format '{{json .Mounts }}' db | jq
|
jq is a JSON processor that needs to be installed separately. And the output is shown as:
1
2
3
4
5
6
7
8
9
10
11
|
[
{
"Source": "/Users/arungupta/couchbase",
"Destination": "/opt/couchbase/var",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
]
|
This shows the source and destination directory. RW
shows that the volume is read/write.
If the container is started using Docker for Mac, then Couchbase Web Console is accessible at http://localhost:8091. The Data Buckets
tab shows the default travel-sample
bucket:
Click on Create New Data Bucket
to create a new data bucket. Give it the name sample
:
The Data Buckets
tab is updated with this newly created bucket:
Now stop and remove the container:
1
2
3
4
|
docker stop db
docker rm db
|
Start the container again using the same command:
1
2
3
|
docker run -d -p 8091-8093:8091-8093 -p 11210:11210 --name db -v ~/couchbase:/opt/couchbase/var couchbase/server:sandbox
|
Data Buckets
tab will show the same two buckets in the Couchbase Web Console.
In this case, if the container is started on a different host then the state would not be available. Or if the host dies then the state is lost.
An alternative and a more robust and foolproof way to manage persistence in containers is using a shared network filesystem such as Ceph, GlusterFS or Network Filesystem. Some other common approaches are to use Docker Volume Plugins like Flocker from ClusterHQ or Software Defined Storage such as PortWorx. All of these storage technique simplify how state of a container can be saved in a multi-container multi-host environment. A future blog will cover these techniques in detail.
Read more details in Managing data in containers.
couchbase.com/containers provide more details about how to run Couchbase in different container frameworks.
More information about Couchbase:
- Couchbase Developer Portal
- Couchbase Forums
- @couchbasedev or @couchbase
Source: blog.couchbase.com/2016/october/persisting-couchbase-data-across-container-restarts
Great post. I found your website perfect for my needs. Very useful info specifically the last part. Thank you for sharing.Also Watch latest movies on your devices for free without any subscription charges using Cinema Box App download.
Here I came to know that we can easily convert our youtube videos to mp3 or mp4 format with the help of convert youtube mp4 site. This website is amazing and very helpful.
hey guys if you are searching for a good amazing adventures game then try roblox robux
when i visiting this site I found cool and interesting here keep sharing kindly check it out easy mobile recharge
I appreciate you sharing this article.Thanks Again. Much obliged.
Extraordinary post. I discovered your site ideal for my necessities. Exceptionally helpful data particularly the last part.
Pakistan Tehreek-e-Insaf (PTI) led by cricketer-turned politician Imran Khan emerged as third major political force in Pakistan after the party’s massive rally at Minar-e-Pakistan in October 2011.
The PTI, founded in 1996 by Imran Khan, wants to made Pakistan a social welfare state. It is the main contender for power against the ruling Pakistan Muslim League-Nawaz leaving the Pakistan People’s Party behind as the main opposition party of the country.
In my opinion, on https://pro-academic-writers.com/blog/essay-writing you can find information about essay writing. It will help you to get a high grade