Neo4j via Docker - SeedCompany/cord-docs GitHub Wiki
Carson's blog post on running Neo4j via Docker:
Ok following up on new db stuff.
It’s pretty simple, we are just swapping from running neo4j directly to running inside of a docker container. Thus general docker knowledge is all that’s needed. I won’t go over it in depth, but I’ll point out a few things.
Basics.
To start the db:
docker-compose up -d db
What is this command doing?
db is the name of the service that’s defined in the docker-compose.yml file. The up action starts the service if it’s not running. -d tells up to run it in the background.
Several other intuitive commands can be ran as well:
docker-compose pull/restart/logs/stop/down db
To access the db query console, you can “Connect to Remote DBMS” in Neo4j Desktop or just go to http://localhost:7474 in your browser :zap:.
Connection to API Server.
Currently the API NodeJS process will still run outside of docker so the connection to the db needs to be done manually. The easiest way to do this is just use the default, which means:
Removing NEO4J_* entries from your .env.local file. :boom:
Customizing.
The db can be customized locally by specifying a docker-compose.override.yml file. This is automatically picked up by docker-compose and allows partial overrides of sections of our versioned docker-compose.yml file. I’ve committed a docker-compose.override.example.yml file as a starting point should you want to do this.
For example, the db is currently ephemeral and data will be wiped on restarts. Should you want to persist data or mount the data on your machine you can specify volumes in the override file.
Loading from dump file.
First we need to mount the data directory. In your docker-compose.override.yml file mentioned above add
services: db: volumes: - ./db-data:/var/lib/neo4j/data The part of the path before the : is the local directory on your machine. Call it whatever you want. Be sure not to commit it too :wink:
Restart the db service to ensure the folder is created and neo4j populates it.
docker-compose restart db
Now drag your .dump file into the ./db-data/dumps folder.
Next we actually run the command to load the dump file. The db service needs to not be running while this is happening so go ahead and stop it. Then run (substituting for the correct dump file name)
docker-compose stop db
docker-compose run db bin/neo4j-admin load --force --from=data/dumps/{filename}.dump
neo4j should give you a progress output and it should take several seconds.
If for some reason you get an error like:
ERROR: No such service: bin/neo4j-admin Try executing into a shell in the container first then run the load command from there.
docker-compose run db /bin/bash
bin/neo4j-admin load --force --from=data/dumps/{filename}.dump
Done! You can start the db service again and the data should be there.
docker-compose up -d db
Creating a dump file Same steps as above to mount the data directory, then:
docker-compose run db bin/neo4j-admin dump --to=data/dumps/{filename}.dump
? I’m happy to answer any questions. :mag: