Browse code

adding docs for Dockerizing Couchbase service

cleaning up instructions, removing redundant output

Signed-off-by: Arun Gupta <arun.gupta@gmail.com>

adding the latest feedback

Signed-off-by: Arun Gupta <arun.gupta@gmail.com>

Arun Gupta authored on 2016/01/05 10:58:28
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,235 @@
0
+<!--[metadata]>
1
+title = "Dockerizing a Couchbase service"
2
+description = "Dockerizing a Couchbase service"
3
+keywords = ["docker, example, package installation, networking, couchbase"]
4
+[menu.main]
5
+parent = "smn_applied"
6
+<![end-metadata]-->
7
+
8
+# Dockerizing a Couchbase service
9
+
10
+This example shows how to start a [Couchbase](http://couchbase.com) server using Docker Compose, configure it using its [REST API](http://developer.couchbase.com/documentation/server/4.0/rest-api/rest-endpoints-all.html), and query it.
11
+
12
+Couchbase is an open source, document-oriented NoSQL database for modern web, mobile, and IoT applications. It is designed for ease of development and Internet-scale performance.
13
+
14
+## Start Couchbase server
15
+
16
+Couchbase Docker images are published at [Docker Hub](https://hub.docker.com/_/couchbase/).
17
+
18
+Start Couchbase server as:
19
+
20
+```
21
+docker run -d --name db -p 8091-8093:8091-8093 -p 11210:11210 couchbase
22
+```
23
+
24
+The purpose of each port exposed is explained at [Couchbase Developer Portal - Network Configuration](http://developer.couchbase.com/documentation/server/4.1/install/install-ports.html).
25
+
26
+Logs can be seen as:
27
+
28
+```
29
+docker logs db
30
+Starting Couchbase Server -- Web UI available at http://<ip>:8091
31
+```
32
+
33
+> **Note**: The examples on this page assume that the Docker Host
34
+> is reachable on `192.168.99.100`. Substitute `192.168.99.100` with
35
+> the actual IP address of your Docker Host.  If you're running
36
+> Docker using Docker machine, you can obtain the IP address
37
+> of the Docker host using `docker-machine ip <MACHINE-NAME>`.
38
+
39
+The logs show that Couchbase console can be accessed at http://192.168.99.100:8091. The default username is `Administrator` and the password is `password`.
40
+
41
+## Configure Couchbase Docker container
42
+
43
+By default, Couchbase server needs to be configured using the console before it can be used. This can be simplified by configuring it using the REST API.
44
+
45
+### Configure memory for Data and Index service
46
+
47
+Data, Query and Index are three different services that can be configured on a Couchbase instance. Each service has different operating needs. For example, Query is CPU intensive operation and so requires a faster processor. Index is disk heavy and so requires a faster solid state drive. Data needs to be read/written fast and so requires more memory.
48
+
49
+Memory needs to be configured for Data and Index service only.
50
+
51
+```
52
+curl -v -X POST http://192.168.99.100:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300
53
+* Hostname was NOT found in DNS cache
54
+*   Trying 192.168.99.100...
55
+* Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
56
+> POST /pools/default HTTP/1.1
57
+> User-Agent: curl/7.37.1
58
+> Host: 192.168.99.100:8091
59
+> Accept: */*
60
+> Content-Length: 36
61
+> Content-Type: application/x-www-form-urlencoded
62
+> 
63
+* upload completely sent off: 36 out of 36 bytes
64
+< HTTP/1.1 401 Unauthorized
65
+< WWW-Authenticate: Basic realm="Couchbase Server Admin / REST"
66
+* Server Couchbase Server is not blacklisted
67
+< Server: Couchbase Server
68
+< Pragma: no-cache
69
+< Date: Wed, 25 Nov 2015 22:48:16 GMT
70
+< Content-Length: 0
71
+< Cache-Control: no-cache
72
+< 
73
+* Connection #0 to host 192.168.99.100 left intact
74
+```
75
+
76
+The command shows an HTTP POST request to the REST endpoint `/pools/default`. The host is the IP address of the Docker machine. The port is the exposed port of Couchbase server. The memory and index quota for the server are passed in the request.
77
+
78
+### Configure Data, Query, and Index services
79
+
80
+All three services, or only one of them, can be configured on each instance. This allows different Couchbase instances to use affinities and setup services accordingly. For example, if Docker host is running a machine with solid-state drive then only Data service can be started.
81
+
82
+```
83
+curl -v http://192.168.99.100:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'
84
+* Hostname was NOT found in DNS cache
85
+*   Trying 192.168.99.100...
86
+* Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
87
+> POST /node/controller/setupServices HTTP/1.1
88
+> User-Agent: curl/7.37.1
89
+> Host: 192.168.99.100:8091
90
+> Accept: */*
91
+> Content-Length: 26
92
+> Content-Type: application/x-www-form-urlencoded
93
+> 
94
+* upload completely sent off: 26 out of 26 bytes
95
+< HTTP/1.1 200 OK
96
+* Server Couchbase Server is not blacklisted
97
+< Server: Couchbase Server
98
+< Pragma: no-cache
99
+< Date: Wed, 25 Nov 2015 22:49:51 GMT
100
+< Content-Length: 0
101
+< Cache-Control: no-cache
102
+< 
103
+* Connection #0 to host 192.168.99.100 left intact
104
+```
105
+
106
+The command shows an HTTP POST request to the REST endpoint `/node/controller/setupServices`. The command shows that all three services are configured for the Couchbase server. The Data service is identified by `kv`, Query service is identified by `n1ql` and Index service identified by `index`.
107
+
108
+### Setup credentials for the Couchbase server
109
+
110
+Sets the username and password credentials that will subsequently be used for managing the Couchbase server.
111
+
112
+```
113
+curl -v -X POST http://192.168.99.100:8091/settings/web -d port=8091 -d username=Administrator -d password=password
114
+* Hostname was NOT found in DNS cache
115
+*   Trying 192.168.99.100...
116
+* Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
117
+> POST /settings/web HTTP/1.1
118
+> User-Agent: curl/7.37.1
119
+> Host: 192.168.99.100:8091
120
+> Accept: */*
121
+> Content-Length: 50
122
+> Content-Type: application/x-www-form-urlencoded
123
+> 
124
+* upload completely sent off: 50 out of 50 bytes
125
+< HTTP/1.1 200 OK
126
+* Server Couchbase Server is not blacklisted
127
+< Server: Couchbase Server
128
+< Pragma: no-cache
129
+< Date: Wed, 25 Nov 2015 22:50:43 GMT
130
+< Content-Type: application/json
131
+< Content-Length: 44
132
+< Cache-Control: no-cache
133
+< 
134
+* Connection #0 to host 192.168.99.100 left intact
135
+{"newBaseUri":"http://192.168.99.100:8091/"}
136
+```
137
+
138
+The command shows an HTTP POST request to the REST endpoint `/settings/web`. The user name and password credentials are passed in the request.
139
+
140
+### Install sample data
141
+
142
+The Couchbase server can be easily load some sample data in the Couchbase instance.
143
+
144
+```
145
+curl -v -u Administrator:password -X POST http://192.168.99.100:8091/sampleBuckets/install -d '["travel-sample"]'
146
+* Hostname was NOT found in DNS cache
147
+*   Trying 192.168.99.100...
148
+* Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
149
+* Server auth using Basic with user 'Administrator'
150
+> POST /sampleBuckets/install HTTP/1.1
151
+> Authorization: Basic QWRtaW5pc3RyYXRvcjpwYXNzd29yZA==
152
+> User-Agent: curl/7.37.1
153
+> Host: 192.168.99.100:8091
154
+> Accept: */*
155
+> Content-Length: 17
156
+> Content-Type: application/x-www-form-urlencoded
157
+> 
158
+* upload completely sent off: 17 out of 17 bytes
159
+< HTTP/1.1 202 Accepted
160
+* Server Couchbase Server is not blacklisted
161
+< Server: Couchbase Server
162
+< Pragma: no-cache
163
+< Date: Wed, 25 Nov 2015 22:51:51 GMT
164
+< Content-Type: application/json
165
+< Content-Length: 2
166
+< Cache-Control: no-cache
167
+< 
168
+* Connection #0 to host 192.168.99.100 left intact
169
+[]
170
+```
171
+
172
+The command shows an HTTP POST request to the REST endpoint `/sampleBuckets/install`. The name of the sample bucket is passed in the request.
173
+
174
+Congratulations, you are now running a Couchbase container, fully configured using the REST API.
175
+
176
+## Query Couchbase using CBQ
177
+
178
+[CBQ](http://developer.couchbase.com/documentation/server/4.1/cli/cbq-tool.html), short for Couchbase Query, is a CLI tool that allows to create, read, update, and delete JSON documents on a Couchbase server. This tool is installed as part of the Couchbase Docker image.
179
+
180
+Run CBQ tool:
181
+
182
+```
183
+docker run -it --link db:db couchbase cbq --engine http://db:8093
184
+Couchbase query shell connected to http://db:8093/ . Type Ctrl-D to exit.
185
+cbq>
186
+```
187
+
188
+`--engine` parameter to CBQ allows to specify the Couchbase server host and port running on the Docker host. For host, typically the host name or IP address of the host where Couchbase server is running is provided. In this case, the container name used when starting the container, `db`, can be used. `8093` port listens for all incoming queries.
189
+
190
+Couchbase allows to query JSON documents using [N1QL](http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/index.html). N1QL is a comprehensive, declarative query language that brings SQL-like query capabilities to JSON documents.
191
+
192
+Query the database by running a N1QL query:
193
+
194
+```
195
+cbq> select * from `travel-sample` limit 1;
196
+{
197
+    "requestID": "97816771-3c25-4a1d-9ea8-eb6ad8a51919",
198
+    "signature": {
199
+        "*": "*"
200
+    },
201
+    "results": [
202
+        {
203
+            "travel-sample": {
204
+                "callsign": "MILE-AIR",
205
+                "country": "United States",
206
+                "iata": "Q5",
207
+                "icao": "MLA",
208
+                "id": 10,
209
+                "name": "40-Mile Air",
210
+                "type": "airline"
211
+            }
212
+        }
213
+    ],
214
+    "status": "success",
215
+    "metrics": {
216
+        "elapsedTime": "60.872423ms",
217
+        "executionTime": "60.792258ms",
218
+        "resultCount": 1,
219
+        "resultSize": 300
220
+    }
221
+}
222
+```
223
+
224
+## Couchbase Web Console
225
+
226
+[Couchbase Web Console](http://developer.couchbase.com/documentation/server/4.1/admin/ui-intro.html) is a console that allows to manage a Couchbase instance. It can be seen at:
227
+
228
+http://192.168.99.100:8091/
229
+
230
+Make sure to replace the IP address with the IP address of your Docker Machine or `localhost` if Docker is running locally.
231
+
232
+![Couchbase Web Console](couchbase/web-console.png)
0 233
new file mode 100644
1 234
Binary files /dev/null and b/docs/examples/couchbase/web-console.png differ