问题描述
与我合作的其他数据库泊坞窗(如Postgres)具有一种机制,可在容器首次启动后将一些初始数据导入其空实例中.这通常是将SQL文件放在特定文件夹中的形式.
Other database dockers that I've worked with (like Postgres) have a mechanism to import some initial data into their empty instance once the container starts for the first time. This is usually in form of putting your SQL files in a specific folder.
我需要对Neo4j做同样的事情.我想组成一个Neo4j docker映像,其中包含一些数据.什么是正确的方法?
I need to do the same for Neo4j. I want to compose a Neo4j docker image with some data in it. What's the right way to do this?
推荐答案
这可以实现...有2个要求:
This could be achieved...There are 2 requirements:
- 设置初始密码,可以使用
bin/neo4j-admin set-initial-password <password>
然后 实现 - 以密文格式
cat import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast
从文件导入数据
- set initial password, which could be achieved using
bin/neo4j-admin set-initial-password <password>
and then - import data from file in cypher format
cat import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast
示例Dockerfile
可能看起来像这样
FROM neo4j:3.2
ENV NEO4J_PASSWD neo4jadmin
ENV NEO4J_AUTH neo4j/${NEO4J_PASSWD}
COPY data.cypher /var/lib/neo4j/import/
VOLUME /data
CMD bin/neo4j-admin set-initial-password ${NEO4J_PASSWD} || true && \
bin/neo4j start && sleep 5 && \
for f in import/*; do \
[ -f "$f" ] || continue; \
cat "$f" | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=${NEO4J_PASSWD} bin/cypher-shell --fail-fast && rm "$f"; \
done && \
tail -f logs/neo4j.log
建筑图片sudo docker build -t neo4j-3.1:loaddata .
运行容器docker run -it --rm --name neo4jtest neo4j-3.1:loaddata
这篇关于Neo4j容器(泊坞窗)中包含初始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!