# Populate DB with script upon building docker image

**URL:** <https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914>\
**Category:** Docker\
**Tags:** docker\
**Created:** [December 1, 2020, 10:06am UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914 "2020-12-01T10:06:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheFoolishPupil](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/thefoolishpupil/32/15293_2.png) [@TheFoolishPupil](https://community.neo4j.com/u/TheFoolishPupil)\
**Post date:** [December 1, 2020, 10:06am UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/1 "2020-12-01T10:06:05Z")

</div>

# Thanks for having a look at my topic 😄

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. ❤

---

<div class="post-metadata">

**Author:** ![dominicvivek06](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dominicvivek06/32/5034_2.png) [@dominicvivek06](https://community.neo4j.com/u/dominicvivek06)\
**Post date:** [December 14, 2020, 11:25pm UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/2 "2020-12-14T23:25:18Z")

</div>

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](https://neo4j.com/docs/operations-manual/current/tools/cypher-shell/)

---

<div class="post-metadata">

**Author:** ![therobbrennan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/therobbrennan/32/14292_2.png) [@therobbrennan](https://community.neo4j.com/u/therobbrennan)\
**Post date:** [January 18, 2021, 7:20pm UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/3 "2021-01-18T19:20:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![therobbrennan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/therobbrennan/32/14292_2.png) [@therobbrennan](https://community.neo4j.com/u/therobbrennan)\
**Post date:** [January 19, 2021, 2:24am UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/4 "2021-01-19T02:24:01Z")

</div>

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

Example `docker-compose.yml` - [heimdall/docker-compose.yml at main · TheRobBrennan/heimdall · GitHub](https://github.com/TheRobBrennan/heimdall/blob/main/docker-compose.yml)

Example `Dockerfile` with a `wrapper.sh` script that handles importing data - [heimdall/neo4j/v4.x.x at main · TheRobBrennan/heimdall · GitHub](https://github.com/TheRobBrennan/heimdall/tree/main/neo4j/v4.x.x)

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\_\_](https://github.com/TheRobBrennan/heimdall/tree/main/neo4j/ __seed__ )

---

<div class="post-metadata">

**Author:** ![dominicvivek06](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dominicvivek06/32/5034_2.png) [@dominicvivek06](https://community.neo4j.com/u/dominicvivek06)\
**Post date:** [January 24, 2021, 12:43am UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/5 "2021-01-24T00:43:45Z")

</div>

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

> **[Neo4j - Seed Docker with Data - Dominic KUMAR's blog](https://www.dominickumar.com/blog/neo4j-seed-docker-with-data/)**
>
> Sometimes, during the project lifecycle, there is a need to quickly start a Neo4j docker with seeded data for QA or UAT environments. Creating a “vanilla” neo4j docker and executing all the data loader cypher queries takes huge amount of time. To...

---

<div class="post-metadata">

**Author:** ![therobbrennan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/therobbrennan/32/14292_2.png) [@therobbrennan](https://community.neo4j.com/u/therobbrennan)\
**Post date:** [January 24, 2021, 1:00am UTC](https://community.neo4j.com/t/populate-db-with-script-upon-building-docker-image/29914/6 "2021-01-24T01:00:53Z")

</div>

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