-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
FROM ubuntu:16.04 | ||
|
||
MAINTAINER Couchbase Docker Team <[email protected]> | ||
|
||
# Install dependencies: | ||
# runit: for container process management | ||
# wget: for downloading .deb | ||
# python-httplib2: used by CLI tools | ||
# chrpath: for fixing curl, below | ||
# tzdata: timezone info used by some N1QL functions | ||
# Additional dependencies for system commands used by cbcollect_info: | ||
# lsof: lsof | ||
# lshw: lshw | ||
# sysstat: iostat, sar, mpstat | ||
# net-tools: ifconfig, arp, netstat | ||
# numactl: numactl | ||
RUN apt-get update && \ | ||
apt-get install -yq runit wget python-httplib2 chrpath tzdata \ | ||
lsof lshw sysstat net-tools numactl && \ | ||
apt-get autoremove && apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
ARG CB_VERSION=5.1.1 | ||
ARG CB_RELEASE_URL=https://packages.couchbase.com/releases | ||
ARG CB_PACKAGE=couchbase-server-community_5.1.1-ubuntu16.04_amd64.deb | ||
ARG CB_SHA256=b8d15af64710c61f8a98218c632becb400feec8a99a593f8e76aa3320fa58bbb | ||
|
||
ENV PATH=$PATH:/opt/couchbase/bin:/opt/couchbase/bin/tools:/opt/couchbase/bin/install | ||
|
||
# Create Couchbase user with UID 1000 (necessary to match default | ||
# boot2docker UID) | ||
RUN groupadd -g 1000 couchbase && useradd couchbase -u 1000 -g couchbase -M | ||
|
||
# Install couchbase | ||
RUN export INSTALL_DONT_START_SERVER=1 && \ | ||
wget -N $CB_RELEASE_URL/$CB_VERSION/$CB_PACKAGE && \ | ||
echo "$CB_SHA256 $CB_PACKAGE" | sha256sum -c - && \ | ||
dpkg -i ./$CB_PACKAGE && rm -f ./$CB_PACKAGE | ||
|
||
# Add runit script for couchbase-server | ||
COPY scripts/run /etc/service/couchbase-server/run | ||
RUN chown -R couchbase:couchbase /etc/service | ||
|
||
# Add dummy script for commands invoked by cbcollect_info that | ||
# make no sense in a Docker container | ||
COPY scripts/dummy.sh /usr/local/bin/ | ||
RUN ln -s dummy.sh /usr/local/bin/iptables-save && \ | ||
ln -s dummy.sh /usr/local/bin/lvdisplay && \ | ||
ln -s dummy.sh /usr/local/bin/vgdisplay && \ | ||
ln -s dummy.sh /usr/local/bin/pvdisplay | ||
|
||
# Fix curl RPATH | ||
RUN chrpath -r '$ORIGIN/../lib' /opt/couchbase/bin/curl | ||
|
||
# Add bootstrap script | ||
COPY scripts/entrypoint.sh / | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD ["couchbase-server"] | ||
|
||
# 8091: Couchbase Web console, REST/HTTP interface | ||
# 8092: Views, queries, XDCR | ||
# 8093: Query services (4.0+) | ||
# 8094: Full-text Search (4.5+) | ||
# 11207: Smart client library data node access (SSL) | ||
# 11210: Smart client library/moxi data node access | ||
# 11211: Legacy non-smart client library data node access | ||
# 18091: Couchbase Web console, REST/HTTP interface (SSL) | ||
# 18092: Views, query, XDCR (SSL) | ||
# 18093: Query services (SSL) (4.0+) | ||
# 18094: Full-text Search (SSL) (4.5+) | ||
EXPOSE 8091 8092 8093 8094 11207 11210 11211 18091 18092 18093 18094 | ||
VOLUME /opt/couchbase/var | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
|
||
This README will guide you through running Couchbase Server with Docker Containers. | ||
|
||
[Couchbase Server](http://www.couchbase.com/nosql-databases/couchbase-server) is a NoSQL document database with a distributed architecture for performance, scalability, and availability. It enables developers to build applications easier and faster by leveraging the power of SQL with the flexibility of JSON. | ||
|
||
For additional questions and feedback, please visit the [Couchbase Forums](https://forums.couchbase.com/) or [Stack Overflow](http://stackoverflow.com/questions/tagged/couchbase). | ||
|
||
# QuickStart with Couchbase Server and Docker | ||
|
||
Here is how to get a single node Couchbase Server cluster running on Docker containers: | ||
|
||
**Step - 1 :** Run Couchbase Server docker container | ||
|
||
`docker run -d --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase` | ||
|
||
**Step - 2 :** Next, visit `http://localhost:8091` on the host machine to see the Web Console to start Couchbase Server setup. | ||
|
||
![setup splash screen](https://raw.githubusercontent.com/cihanb/docker/master/generate/resources/couchbase-server/images/setup-initial.jpg) | ||
|
||
Walk through the Setup wizard and accept the default values. | ||
|
||
- Note: You may need to lower the RAM allocated to various services to fit within the bounds of the resource of the containers. | ||
- Enable the beer-sample bucket to load some sample data. | ||
|
||
![setup step-1 screen](https://raw.githubusercontent.com/cihanb/docker/master/generate/resources/couchbase-server/images/setup-step1.jpg) | ||
|
||
**Note :** For detailed information on configuring the Server, see [Initial Couchbase Server Setup](http://developer.couchbase.com/documentation/server/4.5/install/init-setup.html). | ||
|
||
## Running A N1QL Query on the Couchbase Server Cluster | ||
|
||
N1QL is the SQL based query language for Couchbase Server. Simply switch to the Query tab on the Web Console at `http://localhost:8091` and run the following N1QL Query in the query window: | ||
|
||
```SELECT name FROM `beer-sample` WHERE brewery_id ="mishawaka_brewing";``` | ||
|
||
You can also execute N1QL queries from the commandline. To run a query from command line query tool, run the interactive shell on the container: | ||
|
||
`docker exec -it db sh` | ||
|
||
Then, navigate to the `bin` directory under Couchbase Server installation and run cbq command line tool and execute the N1QL Query on `beer-sample` bucket | ||
|
||
`/opt/couchbase/bin/cbq` | ||
|
||
```cbq> SELECT name FROM `beer-sample` WHERE brewery_id ="mishawaka_brewing";``` | ||
|
||
For more query samples, refer to the [Running your first N1QL query](http://developer.couchbase.com/documentation/server/4.5/getting-started/first-n1ql-query.html) guide. | ||
|
||
## Connect to the Couchbase Server Cluster via Applications and SDKs | ||
Couchbase Server SDKs comes in many languages: C SDK 2.4/2.5 Go, Java, .NET, Node.js, PHP, Python. Simply run your application through the Couchbase Server SDK of your choice on the host, and point it to http://localhost:8091/pools to connect to the container. | ||
|
||
For running a sample application, refer to the [Running a sample Web app](http://developer.couchbase.com/documentation/server/4.5/travel-app/index.html) guide. | ||
|
||
# Requirements and Best Practices | ||
|
||
## Container Requirements | ||
|
||
Official Couchbase Server containers on Docker Hub are based on Ubuntu 14.04. | ||
|
||
**Docker Container Resource Requirements :** For minimum container requirements, you can follow [Couchbase Server minimum HW recommendations](http://developer.couchbase.com/documentation/server/current/install/pre-install.html) for development, test and production environments. | ||
|
||
## Best Practices | ||
|
||
**Avoid a Single Point of Failure :** Couchbase Server's resilience and high-availability are achieved through creating a cluster of independent nodes and replicating data between them so that any individual node failure doesn't lead to loss of access to your data. In a containerized environment, if you were to run multiple nodes on the same piece of physical hardware, you can inadvertently re-introduce a single point of failure. In environments where you control VM placement, we advise ensuring each Couchbase Server node runs on a different piece of physical hardware. | ||
|
||
**Sizing your containers :** Physical hardware performance characteristics are well understood. Even though containers insert a lightweight layer between Couchbase Server and the underlying OS, there is still a small overhead in running Couchbase Server in containers. For stability and better performance predictability, It is recommended to have at least 2 cores dedicated to the container in development environments and 4 cores dedicated to the container rather than shared across multiple containers for Couchbase Server instances running in production. With an over-committed environment you can end up with containers competing with each other causing unpredictable performance and sometimes stability issues. | ||
|
||
**Map Couchbase Node Specific Data to a Local Folder :** A Couchbase Server Docker container will write all persistent and node-specific data under the directory /opt/couchbase/var by default. It is recommended to map this directory to a directory on the host file system using the `-v` option to `docker run` to get persistence and performance. | ||
|
||
- Persistence: Storing `/opt/couchbase/var` outside the container with the `-v` option allows you to delete the container and recreate it later without losing the data in Couchbase Server. You can even update to a container running a later release/version of Couchbase Server without losing your data. | ||
- Performance: In a standard Docker environment using a union file system, leaving /opt/couchbase/var inside the container results in some amount of performance degradation. | ||
|
||
> NOTE for SELinux : If you have SELinux enabled, mounting the host volumes in a container requires an extra step. Assuming you are mounting the `~/couchbase` directory on the host file system, you need to run the following command once before running your first container on that host: | ||
> | ||
> `mkdir ~/couchbase && chcon -Rt svirt_sandbox_file_t ~/couchbase` | ||
**Running the container as non-root user :** Some environments forbid running processes owned by "root". Normally Couchbase Server itself runs in the container as the user "couchbase", but some process-management tools run as "root". To avoid this you may pass the `--user couchbase` to your `docker run` command. Important: If you do this in addition to using `-v` to mount `/opt/couchbase/var` to a host directory, you must ensure that this directory exists first, and that it and all of its contents are owned and writable by user ID 1000 on the host. Failure to do so may cause Couchbase Server to fail to run in ways which are difficult to diagnose. | ||
|
||
**Increase ULIMIT in Production Deployments :** Couchbase Server normally expects the following changes to ulimits: | ||
|
||
```console | ||
ulimit -n 40960 # nofile: max number of open files | ||
ulimit -c unlimited # core: max core file size | ||
ulimit -l unlimited # memlock: maximum locked-in-memory address space | ||
``` | ||
|
||
These ulimit settings are necessary when running under heavy load. If you are just doing light testing and development, you can omit these settings, and everything will still work. | ||
|
||
To set the ulimits in your container, you will need to run Couchbase Docker containers with the following additional --ulimit flags: | ||
|
||
`docker run -d --ulimit nofile=40960:40960 --ulimit core=100000000:100000000 --ulimit memlock=100000000:100000000 --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase` | ||
|
||
Since "unlimited" is not supported as a value, it sets the core and memlock values to 100 GB. If your system has more than 100 GB RAM, you will want to increase this value to match the available RAM on the system. | ||
|
||
> Note:The --ulimit flags only work on Docker 1.6 or later. | ||
**Network Configuration and Ports :** Couchbase Server communicates on many different ports (see the [Couchbase Server documentation](http://docs.couchbase.com/admin/admin/Install/install-networkPorts.html)). Also, it is generally not supported that the cluster nodes be placed behind any NAT. For these reasons, Docker's default networking configuration is not ideally suited to Couchbase Server deployments. For production deployments it is recomended to use `--net=host` setting to avoid performance and reliability issues. | ||
|
||
# Multi Node Couchbase Server Cluster Deployment Topologies | ||
|
||
With multi node Couchbase Server clusters, there are 2 popular topologies. | ||
|
||
## All Couchbase Server containers on one physical machine | ||
|
||
This model is commonly used for scale-minimized deployments simulating production deployments for development and test purposes. Placing all containers on a single physical machine means all containers will compete for the same resources. Placing all containers on a single physical machine also eliminates the built-in protection against Couchbase Server node failures with replication when the single physical machine fail, all containers experience unavailability at the same time loosing all replicas. These restrictions may be acceptable for test systems, however it isn’t recommended for applications in production. | ||
|
||
You can find more details on setting up Couchbase Server in this topology in Couchbase Server [documentation](http://developer.couchbase.com/documentation/server/4.5/install/docker-deploy-multi-node-cluster.html). | ||
|
||
┌──────────────────────────────────────────────────────────┐ | ||
│ Host OS (Linux) │ | ||
│ │ | ||
│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ | ||
│ │ Container OS │ │ Container OS │ │ Container OS │ │ | ||
│ │ (Ubuntu) │ │ (Ubuntu) │ │ (Ubuntu) │ │ | ||
│ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ | ||
│ │ │ Couchbase │ │ │ │ Couchbase │ │ │ │ Couchbase │ │ │ | ||
│ │ │ Server │ │ │ │ Server │ │ │ │ Server │ │ │ | ||
│ │ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │ │ | ||
│ └───────────────┘ └───────────────┘ └───────────────┘ │ | ||
└──────────────────────────────────────────────────────────┘ | ||
|
||
|
||
## Each Couchbase Server container on its own machine | ||
|
||
This model is commonly used for production deployments. It prevents Couchbase Server nodes from stepping over each other and gives you better performance predictability. This is the supported topology in production with Couchbase Server 4.5 and higher. | ||
|
||
You can find more details on setting up Couchbase Server in this topology in Couchbase Server [documentation](http://developer.couchbase.com/documentation/server/4.5/install/docker-deploy-multi-node-cluster.html). | ||
|
||
┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ | ||
│ Host OS (Linux) │ │ Host OS (Linux) │ │ Host OS (Linux) │ | ||
│ ┌─────────────────┐ │ │ ┌─────────────────┐ │ │ ┌─────────────────┐ │ | ||
│ │ Container OS │ │ │ │ Container OS │ │ │ │ Container OS │ │ | ||
│ │ (Ubuntu) │ │ │ │ (Ubuntu) │ │ │ │ (Ubuntu) │ │ | ||
│ │ ┌───────────┐ │ │ │ │ ┌───────────┐ │ │ │ │ ┌───────────┐ │ │ | ||
│ │ │ Couchbase │ │ │ │ │ │ Couchbase │ │ │ │ │ │ Couchbase │ │ │ | ||
│ │ │ Server │ │ │ │ │ │ Server │ │ │ │ │ │ Server │ │ │ | ||
│ │ └───────────┘ │ │ │ │ └───────────┘ │ │ │ │ └───────────┘ │ │ | ||
│ └─────────────────┘ │ │ └─────────────────┘ │ │ └─────────────────┘ │ | ||
└───────────────────────┘ └───────────────────────┘ └───────────────────────┘ | ||
|
||
# Additional References | ||
|
||
- [Couchbase Server and Containers](http://www.couchbase.com/containers) | ||
- [Getting Started with Couchbbase Server and Docker](http://developer.couchbase.com/documentation/server/4.5/install/getting-started-docker.html) | ||
- Detailed Walk-through for [Deploying Couchbase Server on Docker Containers](http://developer.couchbase.com/documentation/server/4.5/install/deploy-with-docker-hub.html) | ||
|
||
# Licensing | ||
|
||
Couchbase Server comes in 2 Editions: Enterprise Edition and Community Edition. You can find details on the differences between the 2 and licensing details on the [Couchbase Server Editions](http://developer.couchbase.com/documentation/server/4.5/introduction/editions.html) page. | ||
|
||
- Enterprise Edition -- free for development, testing and POCs. Requires a paid subscription for production deployment. Please refer to the [subscribe](http://www.couchbase.com/subscriptions-and-support) page for details on enterprise edition agreements. | ||
|
||
- Community Edition -- free for unrestricted use for community users. | ||
|
||
By default, the `latest` Docker tag points to the latest Enterprise Edition. If you want the Community Edition instead, you should add the appropriate tag, such as | ||
|
||
```console | ||
docker run couchbase:community-4.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
echo "Running in Docker container - $0 not available" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
staticConfigFile=/opt/couchbase/etc/couchbase/static_config | ||
restPortValue=8091 | ||
|
||
# see https://developer.couchbase.com/documentation/server/current/install/install-ports.html | ||
function overridePort() { | ||
portName=$1 | ||
portNameUpper=$(echo $portName | awk '{print toupper($0)}') | ||
portValue=${!portNameUpper} | ||
|
||
# only override port if value available AND not already contained in static_config | ||
if [ "$portValue" != "" ]; then | ||
if grep -Fq "{${portName}," ${staticConfigFile} | ||
then | ||
echo "Don't override port ${portName} because already available in $staticConfigFile" | ||
else | ||
echo "Override port '$portName' with value '$portValue'" | ||
echo "{$portName, $portValue}." >> ${staticConfigFile} | ||
|
||
if [ ${portName} == "rest_port" ]; then | ||
restPortValue=${portValue} | ||
fi | ||
fi | ||
fi | ||
} | ||
|
||
overridePort "rest_port" | ||
overridePort "mccouch_port" | ||
overridePort "memcached_port" | ||
overridePort "query_port" | ||
overridePort "ssl_query_port" | ||
overridePort "fts_http_port" | ||
overridePort "moxi_port" | ||
overridePort "ssl_rest_port" | ||
overridePort "ssl_capi_port" | ||
overridePort "ssl_proxy_downstream_port" | ||
overridePort "ssl_proxy_upstream_port" | ||
|
||
|
||
[[ "$1" == "couchbase-server" ]] && { | ||
|
||
if [ $(whoami) = "couchbase" ]; then | ||
# Ensure that /opt/couchbase/var is owned by user 'couchbase' and | ||
# is writable | ||
if [ ! -w /opt/couchbase/var -o \ | ||
$(find /opt/couchbase/var -maxdepth 0 -printf '%u') != "couchbase" ]; then | ||
echo "/opt/couchbase/var is not owned and writable by UID 1000" | ||
echo "Aborting as Couchbase Server will likely not run" | ||
exit 1 | ||
fi | ||
fi | ||
echo "Starting Couchbase Server -- Web UI available at http://<ip>:$restPortValue" | ||
echo "and logs available in /opt/couchbase/var/lib/couchbase/logs" | ||
exec /usr/sbin/runsvdir-start | ||
} | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
exec 2>&1 | ||
|
||
# Create directories where couchbase stores its data | ||
cd /opt/couchbase | ||
mkdir -p var/lib/couchbase \ | ||
var/lib/couchbase/config \ | ||
var/lib/couchbase/data \ | ||
var/lib/couchbase/stats \ | ||
var/lib/couchbase/logs \ | ||
var/lib/moxi | ||
|
||
chown -R couchbase:couchbase var | ||
if [ $(whoami) = "couchbase" ]; then | ||
exec /opt/couchbase/bin/couchbase-server -- -kernel global_enable_tracing false -noinput | ||
else | ||
exec chpst -ucouchbase /opt/couchbase/bin/couchbase-server -- -kernel global_enable_tracing false -noinput | ||
fi |