How to run RethinkDB with Docker and Docker-Compose

In this guide we are going to explore how to run RethinkDB locally with docker and docker compose. This can be helpful if you want to run RethinkDB locally without installing it in your machine or if you want to run multiple versions of

RethinkDB seamlessly.

# Prerequisites

To follow along, ensure you have the following:

  1. Docker installed locally and permissions to use it to launch containers
  2. Docker compose is installed locally
  3. Basic knowledge of the command line

# Table of content

  1. Using the docker run command
  2. Using the docker-compose tool

# 1. Using the docker run command

We are going to use the¬†docker run¬†command to achieve our goal. The version of RethinkDB that we want is¬†rethinkdb:2.4¬†‚Äď the latest version of RethinkDB image.

Create data dir

mkdir -p ~/apps/rethinkdb/data

Run the container

<meta charset="utf-8">docker run -d \
    --name my-<meta charset="utf-8">rethinkdb \
    -p 8081:8080 \
    -v ~/apps/<meta charset="utf-8">rethinkdb/data:/data \
    rethinkdb:2.4

This is my output

$ docker run -d \
    --name my-rethinkdb \
    -p 8081:8080 \
    -v ~/apps/rethinkdb/data:/data \
    rethinkdb:2.4
Unable to find image 'rethinkdb:2.4' locally
2.4: Pulling from library/rethinkdb
a10c77af2613: Pull complete
66fb6b02a9a0: Pull complete
de316cb29885: Pull complete
1c6dfcaddf3c: Pull complete
276ce5b4b663: Pull complete
Digest: sha256:bf0b74da846cf30f1c422573b6faaba09d3354657e71473312fe90a83f77f9ac
Status: Downloaded newer image for rethinkdb:2.4
90a482ccbb7e5cc6a5a790af8acbcbc2f3587cd263a68f02229fd0c4d9ca1aa1

In the above command:

  • The¬†-d¬†instructs docker container to run as a detached process. It run container in background and print container ID
  • -p¬†is for port mapping. We are instructing the container to expose the container port externally. Container port¬†8080¬†is mapped to host port¬†8081. That means the service can be accessed through¬†localhost:8081
  • The¬†-v¬†directive is used to mount volumes. In our case we are mounting the container volume¬†/data¬†to host path¬†~/apps/rethinkdb/data. Containers are ephemeral devices that will contain its data for the time it is running. Once a container is stopped, its data is lost. Mounting volumes ensures that the data is added to a host path that can be reused when the container is restarted.

To check that our container is running as expected, use the docker ps command:

$ docker ps
CONTAINER ID   IMAGE           COMMAND                  CREATED              STATUS              PORTS                                                             NAMES
90a482ccbb7e   rethinkdb:2.4   "rethinkdb --bind all"   About a minute ago   Up About a minute   28015/tcp, 29015/tcp, 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp   my-rethinkdb

In my case the container is running as my-rethinkdb the name we gave it. We can login to the container using the docker exec command while executing /bin/bash interactively. Here we are checking rethinkdb version with

rethinkdb -v

$ docker exec -it my-rethinkdb /bin/bash
root@90a482ccbb7e:/data# rethinkdb -v
rethinkdb 2.4.1~0buster (CLANG 7.0.1 (tags/RELEASE_701/final))

Point your browser to[server_ip]:8081. You’ll see an administrative UI where you can control the cluster (which so far consists of one server), and play with the query language.

If you need to clean up the container when not in use, you can stop and remove the container using this command:

Stop the container

$ docker stop my-rethinkdb
my-rethinkdb

Remove the container

$ docker rm my-rethinkdb
my-rethinkdb

# 2. Using the docker-compose tool

We can achieve the same functionality with docker-compose. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.

Docker Compose allows you to define the service (RethinkDB in our case) with properties like the image to use, ports to expose, volumes to mount and environment variables.

Here is how we would use docker-compose to achieve the functionality above. Save this as docker-compose.yaml:

version: '3.9'

services:
  <meta charset="utf-8">rethinkdb:
    image: <meta charset="utf-8">rethinkdb:2.4
    ports:
      - 8081:8080
    volumes:
      - ~/apps/rethinkdb/data:/app

Now bring up the containers:

$ docker-compose up -d
Creating tmp_rethinkdb_1 ... done

The commands:

  • up¬†brings up the container
  • -d¬†in a detached mode

Verify the container processes using the ps command:

$ docker-compose ps
     Name               Command          State                               Ports
---------------------------------------------------------------------------------------------------------------
tmp_rethinkdb_1   rethinkdb --bind all   Up      28015/tcp, 29015/tcp, 0.0.0.0:8081->8080/tcp,:::8081->8080/tcp

To login to the container and login to RethinkDB, use this:

$ docker-compose exec rethinkdb /bin/bash
root@13458d52f7ad:/data# rethinkdb -v
rethinkdb 2.4.1~0buster (CLANG 7.0.1 (tags/RELEASE_701/final))

You can now access the rethinkdb container in port 8081 using the web interface.

# Conclusion

In this guide we managed to run RethinkDB as a container in our system, we explored using the docker run command while passing the required arguments an alternative approach of simplifying the process with docker-compose

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy