github.com/45cali/docker@v1.11.1/docs/examples/couchbase.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Dockerizing a Couchbase service"
     4  description = "Dockerizing a Couchbase service"
     5  keywords = ["docker, example, package installation, networking, couchbase"]
     6  [menu.main]
     7  parent = "engine_dockerize"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Dockerizing a Couchbase service
    12  
    13  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.
    14  
    15  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.
    16  
    17  ## Start Couchbase server
    18  
    19  Couchbase Docker images are published at [Docker Hub](https://hub.docker.com/_/couchbase/).
    20  
    21  Start Couchbase server as:
    22  
    23  ```
    24  docker run -d --name db -p 8091-8093:8091-8093 -p 11210:11210 couchbase
    25  ```
    26  
    27  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).
    28  
    29  Logs can be seen as:
    30  
    31  ```
    32  docker logs db
    33  Starting Couchbase Server -- Web UI available at http://<ip>:8091
    34  ```
    35  
    36  > **Note**: The examples on this page assume that the Docker Host
    37  > is reachable on `192.168.99.100`. Substitute `192.168.99.100` with
    38  > the actual IP address of your Docker Host.  If you're running
    39  > Docker using Docker machine, you can obtain the IP address
    40  > of the Docker host using `docker-machine ip <MACHINE-NAME>`.
    41  
    42  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`.
    43  
    44  ## Configure Couchbase Docker container
    45  
    46  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.
    47  
    48  ### Configure memory for Data and Index service
    49  
    50  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.
    51  
    52  Memory needs to be configured for Data and Index service only.
    53  
    54  ```
    55  curl -v -X POST http://192.168.99.100:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300
    56  * Hostname was NOT found in DNS cache
    57  *   Trying 192.168.99.100...
    58  * Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
    59  > POST /pools/default HTTP/1.1
    60  > User-Agent: curl/7.37.1
    61  > Host: 192.168.99.100:8091
    62  > Accept: */*
    63  > Content-Length: 36
    64  > Content-Type: application/x-www-form-urlencoded
    65  >
    66  * upload completely sent off: 36 out of 36 bytes
    67  < HTTP/1.1 401 Unauthorized
    68  < WWW-Authenticate: Basic realm="Couchbase Server Admin / REST"
    69  * Server Couchbase Server is not blacklisted
    70  < Server: Couchbase Server
    71  < Pragma: no-cache
    72  < Date: Wed, 25 Nov 2015 22:48:16 GMT
    73  < Content-Length: 0
    74  < Cache-Control: no-cache
    75  <
    76  * Connection #0 to host 192.168.99.100 left intact
    77  ```
    78  
    79  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.
    80  
    81  ### Configure Data, Query, and Index services
    82  
    83  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.
    84  
    85  ```
    86  curl -v http://192.168.99.100:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'
    87  * Hostname was NOT found in DNS cache
    88  *   Trying 192.168.99.100...
    89  * Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
    90  > POST /node/controller/setupServices HTTP/1.1
    91  > User-Agent: curl/7.37.1
    92  > Host: 192.168.99.100:8091
    93  > Accept: */*
    94  > Content-Length: 26
    95  > Content-Type: application/x-www-form-urlencoded
    96  >
    97  * upload completely sent off: 26 out of 26 bytes
    98  < HTTP/1.1 200 OK
    99  * Server Couchbase Server is not blacklisted
   100  < Server: Couchbase Server
   101  < Pragma: no-cache
   102  < Date: Wed, 25 Nov 2015 22:49:51 GMT
   103  < Content-Length: 0
   104  < Cache-Control: no-cache
   105  <
   106  * Connection #0 to host 192.168.99.100 left intact
   107  ```
   108  
   109  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`.
   110  
   111  ### Setup credentials for the Couchbase server
   112  
   113  Sets the username and password credentials that will subsequently be used for managing the Couchbase server.
   114  
   115  ```
   116  curl -v -X POST http://192.168.99.100:8091/settings/web -d port=8091 -d username=Administrator -d password=password
   117  * Hostname was NOT found in DNS cache
   118  *   Trying 192.168.99.100...
   119  * Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
   120  > POST /settings/web HTTP/1.1
   121  > User-Agent: curl/7.37.1
   122  > Host: 192.168.99.100:8091
   123  > Accept: */*
   124  > Content-Length: 50
   125  > Content-Type: application/x-www-form-urlencoded
   126  >
   127  * upload completely sent off: 50 out of 50 bytes
   128  < HTTP/1.1 200 OK
   129  * Server Couchbase Server is not blacklisted
   130  < Server: Couchbase Server
   131  < Pragma: no-cache
   132  < Date: Wed, 25 Nov 2015 22:50:43 GMT
   133  < Content-Type: application/json
   134  < Content-Length: 44
   135  < Cache-Control: no-cache
   136  <
   137  * Connection #0 to host 192.168.99.100 left intact
   138  {"newBaseUri":"http://192.168.99.100:8091/"}
   139  ```
   140  
   141  The command shows an HTTP POST request to the REST endpoint `/settings/web`. The user name and password credentials are passed in the request.
   142  
   143  ### Install sample data
   144  
   145  The Couchbase server can be easily load some sample data in the Couchbase instance.
   146  
   147  ```
   148  curl -v -u Administrator:password -X POST http://192.168.99.100:8091/sampleBuckets/install -d '["travel-sample"]'
   149  * Hostname was NOT found in DNS cache
   150  *   Trying 192.168.99.100...
   151  * Connected to 192.168.99.100 (192.168.99.100) port 8091 (#0)
   152  * Server auth using Basic with user 'Administrator'
   153  > POST /sampleBuckets/install HTTP/1.1
   154  > Authorization: Basic QWRtaW5pc3RyYXRvcjpwYXNzd29yZA==
   155  > User-Agent: curl/7.37.1
   156  > Host: 192.168.99.100:8091
   157  > Accept: */*
   158  > Content-Length: 17
   159  > Content-Type: application/x-www-form-urlencoded
   160  >
   161  * upload completely sent off: 17 out of 17 bytes
   162  < HTTP/1.1 202 Accepted
   163  * Server Couchbase Server is not blacklisted
   164  < Server: Couchbase Server
   165  < Pragma: no-cache
   166  < Date: Wed, 25 Nov 2015 22:51:51 GMT
   167  < Content-Type: application/json
   168  < Content-Length: 2
   169  < Cache-Control: no-cache
   170  <
   171  * Connection #0 to host 192.168.99.100 left intact
   172  []
   173  ```
   174  
   175  The command shows an HTTP POST request to the REST endpoint `/sampleBuckets/install`. The name of the sample bucket is passed in the request.
   176  
   177  Congratulations, you are now running a Couchbase container, fully configured using the REST API.
   178  
   179  ## Query Couchbase using CBQ
   180  
   181  [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.
   182  
   183  Run CBQ tool:
   184  
   185  ```
   186  docker run -it --link db:db couchbase cbq --engine http://db:8093
   187  Couchbase query shell connected to http://db:8093/ . Type Ctrl-D to exit.
   188  cbq>
   189  ```
   190  
   191  `--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.
   192  
   193  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.
   194  
   195  Query the database by running a N1QL query:
   196  
   197  ```
   198  cbq> select * from `travel-sample` limit 1;
   199  {
   200      "requestID": "97816771-3c25-4a1d-9ea8-eb6ad8a51919",
   201      "signature": {
   202          "*": "*"
   203      },
   204      "results": [
   205          {
   206              "travel-sample": {
   207                  "callsign": "MILE-AIR",
   208                  "country": "United States",
   209                  "iata": "Q5",
   210                  "icao": "MLA",
   211                  "id": 10,
   212                  "name": "40-Mile Air",
   213                  "type": "airline"
   214              }
   215          }
   216      ],
   217      "status": "success",
   218      "metrics": {
   219          "elapsedTime": "60.872423ms",
   220          "executionTime": "60.792258ms",
   221          "resultCount": 1,
   222          "resultSize": 300
   223      }
   224  }
   225  ```
   226  
   227  ## Couchbase Web Console
   228  
   229  [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:
   230  
   231  http://192.168.99.100:8091/
   232  
   233  Make sure to replace the IP address with the IP address of your Docker Machine or `localhost` if Docker is running locally.
   234  
   235  ![Couchbase Web Console](couchbase/web-console.png)