Aerospike in Docker

Aerospike in Docker

By June 1, 2017Engineering

Recently, we wanted to test our apps in a local environment. Our apps use various services such as Cassandra, Aerospike, Mysql, etc.  Setting up these services locally takes a lot of time for each developer, so we set up those services to run in docker.  In this article we will walk through how to setup Aerospike in docker and initialize the server with user defined functions.

First, we pull the image of centos from the docker repository and install the tar file using wget (and add logrotate which Aerospike uses).

RUN yum -y install logrotate || exit $?

FROM centos

RUN yum -y install tar || exit $?

RUN yum -y install wget || exit $?

We will download Aerospike from the repository and install it:

ENV AEROSPIKE_VERSION=3.5.4
RUN wget “https://www.aerospike.com/artifacts/aerospike-server-community/${AEROSPIKE_VERSION}/aerospike-server-community-${AEROSPIKE_VERSION}-el6.tgz” -O aerospike.tgz || exit $?
RUN mkdir  aerospike || exit $?
RUN tar xzf aerospike.tgz –strip-components=1 -C aerospike || exit $?
RUN cd aerospike && ./asinstall || exit $?

We now have a docker image with Aerospike installed.  We also need to add the user defined functions to the docker image.  The following command will add a user-udf folder into the docker image that has UDFs in it:

ADD user-udf user-udf

Then we expose the ports of Aerospike, so that it can be accessed from other docker containers:

EXPOSE 3000 3001 3002 3003

In our case, we need a script to start the Aerospike server and import the user defined functions.  We can set the script to run using “CMD”:

CMD datapipe-user-udf/bin/start.sh

The following is the content of the start.sh script.  This script will start Aerospike in background process.  It will then import the user defined functions:

/usr/bin/asd –foreground &
sleep 5
/usr/bin/ascli udf-put user-udf/udf/didSet.lua || exit $?
/usr/bin/ascli udf-put user-udf/udf/gidSet.lua || exit $?
/usr/bin/ascli udf-put user-udf/udf/stidSet.lua || exit $?
wait

We can build the Aerospike docker image with the following command:

docker build -t aerospike <aerospike-docker-folder>

Run Aerospike:

docker run -t -p 3000:3000 aerospike

The Aerospike server is now up and running on port 3000:3000 (binds the port on your localhost).
You can access Aerospike through tcp address localhost:3000.

About ShareThis

ShareThis has unlocked the power of global digital behavior by synthesizing social share, interest, and intent data since 2007. Powered by consumer behavior on over three million global domains, ShareThis observes real-time actions from real people on real digital destinations.

Subscribe to our Newsletter

Get the latest news, tips, and updates

Subscribe

Related Content