Search code examples
dockermemgraphdb

Can I run two instances of Memgraph and use data persistence at the same time?


I've found the question that explains that it is possible to run two Memgraph instances at the same time when you are using Docker.

I've used the commands from that answer to run the instances:

  • Fist instance: docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 memgraph/memgraph-platform

  • Second instance: docker run -it -p 7688:7687 -p 7445:7444 -p 3001:3000 memgraph/memgraph-platform

This works OK.

I've modified this commands so that I would have data persistence. First instance runs ok, second one is not brought up; mgconsole is not shown. I don't see any errors.

  • Fist instance: docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 -v mg_lib:/var/lib/memgraph memgraph/memgraph-platform

  • Second instance: docker run -it -p 7688:7687 -p 7445:7444 -p 3001:3000 -v mg_lib:/var/lib/memgraph memgraph/memgraph-platform

What causes this?


Solution

  • When running two Docker instances at the same time besides different port numbers it is important to use different volumes for data persistance. The correct commands would be:

    docker run -it -p 7687:7687 -p 3000:3000 -p 7444:7444 -v mg_lib:/var/lib/memgraph memgraph/memgraph-platform
    
    docker run -it -p 7688:7687 -p 3001:3000 -p 7445:7444 -v mg_lib2:/var/lib/memgraph memgraph/memgraph-platform