Populate DB with script upon building docker image

Thanks for having a look at my topic :smile:

I'm looking for some advice regarding best practices for populating a database upon initial build of a docker container. I have a docker-compose file that launches an instance of neo4j-4.2.0-community, alongside a python application that will be interacting with the database. I have a cypher script, and a csv file, that together populate the db with appropriate test data. My question is then:

What is the recommended way to store/execute the script/csv file such that it is of least encumbrance to collaborators? That is, ideally I don't need to tell them to find the csv file in version control and paste it into the neo4j browser prompt. I also don't want to track the database in version control.

As side note that may or may not be relevant; I noticed that in neo4j browser there is a tab for local scripts Is there a way I can mount this as a volume so that when a collaborator creates the containers, they can simply click on the saved script to populate the db? That would be sufficient and actually preferable to having the script run directly upon startup or something similar.

Any and all help is much appreciated and please let me know if you want further information. :heart:

You can add the "bootstrapping" cypher script and shell script to execute the cypher into git, then use "ADD" in docker to get the files.

At the end of the Dockerfile, use "RUN" to execute the cypher-shell loading scripts. (use -f parameter)

Alternatively you can used Build ( populate DB) and Deploy docker-compose files for DevOps orchestrations.

Cypher-Shell

Oh I didn't know that was possible - but that's cool.

Do you have an example Dockerfile and/or docker-compose.yml snippet I could refer to?

Just to round out the thread, I'm sharing my solution of how to accomplish this :nerd_face:

Example docker-compose.yml - heimdall/docker-compose.yml at main · TheRobBrennan/heimdall · GitHub

Example Dockerfile with a wrapper.sh script that handles importing data - heimdall/neo4j/v4.x.x at main · TheRobBrennan/heimdall · GitHub

Example Cypher script that is used to create seed data for nodes and relationships - as well as defining constraints - https://github.com/TheRobBrennan/heimdall/tree/main/neo4j/__seed__

Hi @therobbrennan , apologies for the delay. here is my blog as an example.

That's so awesome. Thank you for sharing ::fist bump::