Running GridDB in Docker

Containers have been a hot topic in recent years and they’re a surprisingly easy method of starting out with any new software: GridDB is no exception. With just a few easy steps you’re able to deploy a GridDB Container in Docker to test and develop code.

The basic process is:

  1. Download Docker and Other Prerequisites.

  2. Build a Docker Image.

  3. Run the Container

  4. Build and Run Sample Code

This post is not meant to be all encompassing, just a quick howto on running the GridDB server in Docker so that a developer could try some basic code. There are many other considerations if you wanted to put GridDB and Docker into a production environment with external access.

Download Docker and Prerequisites

  1. Download and install Docker from https://www.docker.com/get-docker for your preferred platform. For this article, we used Docker on MacOSX.

  2. Download Oracle JDK (the Linux x64 RPM pacakge) from: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  3. Using Docker, download the CentOS Base Image. 6.7, 6.8, or 6.9 will work.

  4. $ docker pull centos:6.8
    6.8: Pulling from library/centos
    67f15db7c18f: Pull complete
    Digest: sha256:37ee2dcd9a3a430136b566efb4aa1111ed332bfdef8b0de51a25d26891689fd7
    Status: Downloaded newer image for centos:6.8
    

Build A Docker Image

First create an empty directory to store the files necessary to create a Docker image.

1. Place the Java JDK you previously downloaded in this directory.
2. Create a file named griddb.sh that will be used by the Dockerfile with the following content:

#!/bin/bash
export GS_HOME=/var/lib/gridstore/
export GS_LOG=/var/lib/gridstore/log

3. Create the a file named “Dockerfile” with the following content:

FROM centos:6.8

RUN set -x &&\
HOST=`hostname` && \
sed -i "s/^\(HOSTNAME=\).*/\1$HOST/" /etc/sysconfig/network && \
rpm -Uvh https://github.com/griddb/griddb_nosql/releases/download/v3.0.0/griddb_nosql-3.0.0-1.linux.x86_64.rpm

RUN set -x &&\
su - gsadm -c "gs_passwd admin -p admin"

RUN set -x && \
sed -i -e s/\"clusterName\":\"\"/\"clusterName\":\"dockerGridDB\"/g \
-e s/\"replicationNum\":2/\"replicationNum\":1/g /var/lib/gridstore/conf/gs_cluster.json

ADD jdk-8u121-linux-x64.rpm /tmp

RUN set -x && \
rpm -Uvh /tmp/jdk-8u121-linux-x64.rpm

CMD su - gsadm -c \
"gs_startnode -u admin/admin -w 0 && gs_joincluster -c dockerGridDB -n 1 -u admin/admin" &&\
tail -f /dev/null

Now after you’ve created the Dockerfile you can create the image with the following command:

$ docker build -t docker-griddb .
Step 1/7 : FROM centos:6.8
 ---> ab44245321a8
Step 2/7 : RUN set -x &&	HOST=`hostname` && 	sed -i "s/^\(HOSTNAME=\).*/\1$HOST/" /etc/sysconfig/network && 	rpm -Uvh https://github.com/griddb/griddb_nosql/releases/download/v3.0.0/griddb_nosql-3.0.0-1.linux.x86_64.rpm
 ---> Running in b723cc52a3a6
++ hostname
+ HOST=0de5ce56403a
+ sed -i 's/^\(HOSTNAME=\).*/\10de5ce56403a/' /etc/sysconfig/network
+ rpm -Uvh https://github.com/griddb/griddb_nosql/releases/download/v3.0.0/griddb_nosql-3.0.0-1.linux.x86_64.rpm
Retrieving https://github.com/griddb/griddb_nosql/releases/download/v3.0.0/griddb_nosql-3.0.0-1.linux.x86_64.rpm
Preparing...                ##################################################

------------------------------------------------------------
Information:
  User gsadm and group gridstore have been registered.
  GridDB uses new user and group.
------------------------------------------------------------

griddb_nosql                ##################################################
 ---> e742811e19c1
Removing intermediate container b723cc52a3a6
Step 3/7 : RUN set -x &&	su - gsadm -c "gs_passwd admin -p admin"
 ---> Running in bb1e0fff55d6
+ su - gsadm -c 'gs_passwd admin -p admin'
 ---> 13efc76ae454
Removing intermediate container bb1e0fff55d6
Step 4/7 : RUN set -x && 	sed -i -e s/\"clusterName\":\"\"/\"clusterName\":\"dockerGridDB\"/g 		-e s/\"replicationNum\":2/\"replicationNum\":1/g /var/lib/gridstore/conf/gs_cluster.json
 ---> Running in 7f0e0d4dd443
+ sed -i -e 's/"clusterName":""/"clusterName":"dockerGridDB"/g' -e 's/"replicationNum":2/"replicationNum":1/g' /var/lib/gridstore/conf/gs_cluster.json
 ---> 9fc93177a6d6
Removing intermediate container 7f0e0d4dd443
Step 5/9 : ADD griddb.sh /etc/profile.d/
 ---> 2950c8327419
Removing intermediate container 520da00ea008
Step 6/9 : RUN set -x && 	chmod +x /etc/profile.d/griddb.sh
 ---> Running in 1882151bf8f8
+ chmod +x /etc/profile.d/griddb.sh
 ---> 610c1a75042d
Removing intermediate container 1882151bf8f8
Step 7/7 : ADD jdk-8u121-linux-x64.rpm /tmp
 ---> 82e290734a6d
Removing intermediate container 438a4b84f818
Step 8/9 : RUN set -x && 	rpm -Uvh /tmp/jdk-8u121-linux-x64.rpm
 ---> Running in 73335ba1f265
+ rpm -Uvh /tmp/jdk-8u121-linux-x64.rpm
Preparing...                ##################################################
jdk1.8.0_121                ##################################################
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
 ---> 831d58936710
Removing intermediate container 73335ba1f265
Step 9/9 : CMD su - gsadm -c 	"gs_startnode -u admin/admin -w 0 && gs_joincluster -c dockerGridDB -n 1 -u admin/admin" &&	tail -f /dev/null
 ---> Running in 5143de19c598
 ---> 944a0436f719
Removing intermediate container 5143de19c598
Successfully built 944a0436f719

Run

$ docker run docker-griddb
..
Started node.

You can see your container running in with Docker ps:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f10c6cb4a3af        griddb-docker       "/bin/sh -c 'su - ..."   39 seconds ago      Up 38 seconds                           jovial_morse

The container ID is important as we’ll use it as the argument other docker commands such as exec as demonstrated below to see gs_stat information.

$ docker exec f10c su - gsadm  -c "gs_stat -u admin/admin"
{
    "checkpoint": {
        "endTime": 1491496340738,
        "mode": "RECOVERY_CHECKPOINT",
        "normalCheckpointOperation": 0,
        "pendingPartition": 0,
        "requestedCheckpointOperation": 0,
        "startTime": 1491496340586
    },
    "cluster": {
        "activeCount": 1,
        "clusterName": "dockerGridDB",
        "clusterStatus": "MASTER",
        "designatedCount": 1,
        "loadBalancer": "ACTIVE",
        "master": {
            "address": "172.17.0.2",
            "port": 10040
        },
        "nodeList": [
            {
                "address": "172.17.0.2",
                "port": 10040
            }
        ],
        "nodeStatus": "ACTIVE",
        "notificationMode": "MULTICAST",
        "partitionStatus": "NORMAL",
        "startupTime": "2017-04-06T16:32:18Z",
        "syncCount": 2
    },
    "currentTime": "2017-04-06T16:47:00Z",
    "performance": {
        "batchFree": 0,
        "checkpointFileAllocateSize": 65536,
        "checkpointFileSize": 65536,
        "checkpointFileUsageRate": 0,
        "checkpointMemory": 0,
        "checkpointMemoryLimit": 1073741824,
        "checkpointWriteSize": 0,
        "checkpointWriteTime": 0,
        "currentCheckpointWriteBufferSize": 0,
        "currentTime": 1491497220407,
        "numConnection": 2,
        "numSession": 0,
        "numTxn": 0,
        "peakProcessMemory": 312152064,
        "processMemory": 312152064,
        "recoveryReadSize": 65536,
        "recoveryReadTime": 0,
        "storeCompressionMode": "NO_BLOCK_COMPRESSION",
        "storeDetail": {
            "batchFreeMapData": {
                "storeMemory": 0,
                "storeUse": 0,
                "swapRead": 0,
                "swapWrite": 0
            },
            "batchFreeRowData": {
                "storeMemory": 0,
                "storeUse": 0,
                "swapRead": 0,
                "swapWrite": 0
            },
            "mapData": {
                "storeMemory": 0,
                "storeUse": 0,
                "swapRead": 0,
                "swapWrite": 0
            },
            "metaData": {
                "storeMemory": 0,
                "storeUse": 0,
                "swapRead": 0,
                "swapWrite": 0
            },
            "rowData": {
                "storeMemory": 0,
                "storeUse": 0,
                "swapRead": 0,
                "swapWrite": 0
            }
        },
        "storeMemory": 0,
        "storeMemoryLimit": 1073741824,
        "storeTotalUse": 0,
        "swapRead": 0,
        "swapReadSize": 0,
        "swapReadTime": 0,
        "swapWrite": 0,
        "swapWriteSize": 0,
        "swapWriteTime": 0,
        "syncReadSize": 0,
        "syncReadTime": 0,
        "totalLockConflictCount": 0,
        "totalReadOperation": 0,
        "totalRowRead": 0,
        "totalRowWrite": 0,
        "totalWriteOperation": 0
    },
    "recovery": {
        "progressRate": 1
    },
    "version": "3.0.0-27877 CE"
}

Build and Run Sample Code

There are several ways you could build GridDB source code, such as with Eclipse as demonstrated in the the Documentation, but for this simple case we’ll use the JDK within the container to build a Sample app. Start up a shell in your container with:

$ docker exec -it f10c bash

Then run the following commands:

# export CLASSPATH=/usr/share/java/gridstore.jar:$CLASSPATH
# mkdir gsSample
# cp /usr/griddb-3.0.0/docs/sample/program/Sample1.java gsSample/
# javac gsSample/Sample1.java
# java gsSample/Sample1 239.0.0.1 31999 dockerGridDB admin admin
name=name02 status=false count=2 lob=[65, 66, 67, 68, 69, 70, 71, 72, 73, 74]

Congratulations, your container is able to execute the GridDB Sample. If you want to copy a file from your host to the container, that is easily done using:

$ docker cp sourceFile containerId:destinationPath

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.