NoSQL with Couchbase: Setting everything up with Docker

Docker shipping containers

Welcome to the promised NoSQL with Couchbase series, in these articles we are going to learn how to use a NoSQL database called Couchbase. We are going to investigate and learn what it is extremely good at and what it is not the best at. There is quite a lot of stuff to go through, I am imagining it being enough content for around 5-6 articles and therefore I feel like we have to split it up. This first episode we will focus on installation, and as a bonus, we will also get a quick introduction to another powerful tool called Docker.

Make sure to check out the other articles in the series as well:

  1. NoSQL with Couchbase: Setting everything up with Docker
  2. NoSQL with Couchbase: Getting started
  3. NoSQL with Couchbase: Working with JSON
  4. NoSQL with Couchbase: Querying with N1QL
  5. NoSQL with Couchbase: Creating Indexes that Scale

Docker

Docker is a great way to quickly get up different servers that you need. You might have heard about it, but if not let me give a quick introduction. With Docker, you ship software in something that is referred to as containers. A container is a lightweight, stand-alone and executable that includes all the pieces of what you need to run the software, and only that.

So for example, a container can include a lightweight Linux distro and just your software. This environment is isolated and will prevent conflicts between different people running the containers on different infrastructure.

The reason why I’m bringing up Docker is that I am planning to write articles about NoSQL with Couchbase, and in these articles, we are going to run Couchbase in Docker to make sure that we get it up and running as smooth as possible. Docker is a perfect fit for this task.

Putting Docker to use

In this article, we are going to install a docker container with Couchbase 5.0 community edition in it. The installer can be found at https://www.docker.com/community-edition and there is versions for almost every major operating system; Windows 10, MacOS, Debian, Fedora, CentOS, and more.

If you are still running Windows 7 you will have to install Docker Toolbox instead, but for this article that is considered out of scope. But there should be plenty of guides on how to get started with it.

Installation

The installation is pretty straightforward so you shouldn’t have any issues getting through it. After you’ve got it installed make sure that you enable Docker as an environment variable so that you can use it from any directory for convenience.

After the installation, we will visit the public registry Docker Hub. A registry is a repository where containers are stored and available for download. It is possible to set up and use private registries, but we do not need that since everything that we need is in the public registry.

Searching for Couchbase server we can find the official Couchbase container repository.

There are many different version available for Couchbase, with the most recent impressive release being 5.0.0 that we are going to install. There is a community edition and an enterprise edition. The enterprise edition is actually faster and more optimized than the community edition, but keep in mind that if you are going into production then you need to license it, it is fine though to use for experimenting. But that doesn’t mean that the community edition isn’t good. The community edition is what we will choose for this article and the upcoming Couchbase tutorials.

For the purpose of this tutorial, we do not really care about if the data disappears after a restart. But you should definitely have a look at and use volumes if you wanna run your container for a longer period and be sure that the data survives a crash or a reboot of your server or computer. It is not complicated to set up a volume but it is considered out of scope for this tutorial, see https://docs.docker.com/engine/admin/volumes/volumes/ for good instructions.

Pulling and running the Couchbase container

Open a terminal/cmd window and type the following:

If we want to disable or remove the container we can do it with the following commands:

Shortly after this, you can navigate to localhost:8091, and we are good to go.

Configuring Couchbase

You can tweak the memory requirements if you want, but I recommend leaving them default for now. We can increase/decrease later if we want. I would suggest disabling Search though as we are not gonna use that. Search is the full-text search engine, similar to ElasticSearch. We are more interested in the Query engine. However, if you later want to develop an application where you store longer texts and it should be possible for users to search these longer texts, then I definitely recommend giving the Search service a test.

Choose Memory-Optimized as the Index Storage Setting. Memory-optimized was introduced in Couchbase:4.5.0 and has since then been the go-to setting for the best performance. It’s worth noting though that they consume more RAM than the legacy Standard Global Secondary which runs on the ForestDB engine.

In the 5.0.0 enterprise version we do not have this option, instead, we receive something referred to as the Plasma engine, which is as performant as Memory-optimized but also doesn’t reside everything in the indexes in RAM.

Press next to proceed.

Final words

We have now successfully set up a Couchbase database, wasn’t that easy? In the next article, we will start using the Couchbase database that we just set up.

If you enjoyed the article, I would very much appreciate if you gave it a thumbs up and shared it on social media.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *