Search code examples
dockerinitializationjanusgraph

How to import data into janusgraph docker at startup


I want to run the janusgraph container ready with some data loaded at the time of initialisation.

I've checked the janusgraph docker documentation - https://github.com/JanusGraph/janusgraph-docker but didn't find any information around initialising the container pre loaded with data.

Is there any easy way to do this. I can write a groovy script or a java class to import the data, I just want to know how do I call this at the time of container creation so that once the container is ready it has the data pre-loaded in it.


Solution

  • Maybe you missed that part of the docs but the README.md contains a section Initialization that explains how to load data into JanusGraph when the container starts.

    You just need to create a Groovy script (the file name needs to end on .groovy) and put it into the /docker-entrypoint-initdb.d which lets JanusGraph execute it when the container starts.

    A quick example that is taken directly from that section looks like this:

    1. Create a Groovy script and name it add-vertex-groovy:
    g = traversal().withRemote('conf/remote-graph.properties')
    // add the traversals to initialize the Graph with your data
    g.addV('demigod').property('name', 'hercules').iterate()
    
    1. Put the file in the relevant directory, e.g., by creating a custom Dockerfile:
    FROM janusgraph/janusgraph:0.5.2
        
    COPY add-vertex-groovy /docker-entrypoint-initdb.d/