How to run Arangodb in docker container

How to run Arangodb in docker container

·

4 min read

I came across Arangodb in a project which really required an investigative graph explorer. This use case required investigation of more than 3-degree relationships fairly quickly. That’s when we ditched our transactional database

AQL

Arangodb is a NoSQL datastore which allows us to run graph algorithms and queries easily. Writing a query in Arangodb is done through AQL which is quite similar to writing a loop. The query below is filtering users for a key named “phil”.

FOR doc IN users
    FILTER doc._key == "phil"
    RETURN doc

AQL is mainly a declarative language. The syntax of AQL queries is different from SQL, even if some keywords overlap. Nevertheless, AQL should be easy to understand for anyone with an SQL background.

Foxx Microservices(game changer?)

Traditionally server-side is used as a standalone application that guides the communication between client-side frontend and database, this is actually a bit more complicated, as it has more moving parts if you compare it to what is happening with Foxx microservices in Arangodb.

ArangoDB allows developers to write their data access and domain logic as microservices running directly within the database with native access to in-memory data. The Foxx microservice framework makes it easy to extend ArangoDB’s own REST API with custom HTTP endpoints using modern JavaScript running on Nodejs

If you have used NodJS with express before, it will look quite familiar. A sample implementation is as follows:

'use strict';
const createRouter = require('@arangodb/foxx/router');
const router = createRouter();

module.context.use(router);

const db = require('@arangodb').db;
const errors = require('@arangodb').errors;
const foxxColl = db._collection('myFoxxCollection');
const DOC_NOT_FOUND = errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code;

router.post('/entries', function (req, res) {
  const data = req.body;
  const meta = foxxColl.save(req.body);
  res.send(Object.assign(data, meta));
})
.body(joi.object().required(), 'Entry to store in the collection.')
.response(joi.object().required(), 'Entry stored in the collection.')
.summary('Store an entry')
.description('Stores an entry in the "myFoxxCollection" collection.');

router.get('/entries/:key', function (req, res) {
  try {
    const data = foxxColl.document(req.pathParams.key);
    res.send(data)
  } catch (e) {
    if (!e.isArangoError || e.errorNum !== DOC_NOT_FOUND) {
      throw e;
    }
    res.throw(404, 'The entry does not exist', e);
  }
})
.pathParam('key', joi.string().required(), 'Key of the entry.')
.response(joi.object().required(), 'Entry stored in the collection.')
.summary('Retrieve an entry')
.description('Retrieves an entry from the "myFoxxCollection" collection by key.');

Running on docker

Running an Arangodb instance using docker is quite straightforward, it just requires you to pull the image from docker-hub then run with a few configurations in place.

To run this you must have docker installed, its really quick to install docker on mac with few clicks, you can follow this link: https://docs.docker.com/docker-for-mac/install/

docker pull arangodb:3.6

docker run \
 -e ARANGO_ROOT_PASSWORD=password \
 -p 8529:8529 \
 -v /arangodb:/var/lib/arangodb3 \
 -v /arangodb/logs/:/var/log/arangodb3 \
 --restart always \
 --name arangodb \
 -d arangodb:3.6 \
 --log.level warning \

After you run this command go to localhost:8529 to access the dashboard: