使用来自cypher文件的初始数据创建自定义Neo4j Docker映像 [英] Create custom Neo4j Docker image with intial data from cypher file
问题描述
当您启动容器时,我尝试创建neo4j的docker映像,该映像已经提供了一些数据.对于我的方法,我继承了neo4j docker映像,并通过neo4j cypher shell添加了一些数据.但是,当我构建映像并从中运行容器时,数据未出现在数据库中,但是设置了自定义密码. 这是我当前的dockerfile:
From neo4j:3.4
ENV NEO4J_AUTH=neo4j/password
COPY data.cypher /var/lib/neo4j/import/
USER neo4j
RUN bin/neo4j-admin set-initial-password password || true && \
bin/neo4j start && sleep 5 && \
cat /var/lib/neo4j/import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=password /var/lib/neo4j/bin/cypher-shell --fail-fast
CMD [neo4j]
我还在data.cypher文件中添加了一个匹配查询,以确保shell将数据添加到neo4j中.将/data
定义为neo4j图像中的体积,也许可以做些什么?
我正在使用 Bierbarbar 的方法.我克服了以下两个陷阱后就可以正常工作了:
首先,$NEO4J_HOME/data
被符号链接到/data
,这似乎具有权限问题.更改默认数据文件夹:通过将dbms.directories.data=mydata
行添加到$NEO4J_HOME/conf/neo4j.conf
来解决此问题.
第二,确保data.cypher
文件包含用于cypher-shell的正确格式:1)在每个cypher状态的末尾都需要使用分号; 2)在cypher-shell
的某些版本(或所有版本?)中有:begin
和:commit
命令
I tried create an docker image of neo4j that already provide some data, when you start an container. For my approach I inherited from the neo4j docker image, added some data via the neo4j cypher shell. But when i build the image and run a container from it the data did not appear in the database but the custom password is set. This is my current dockerfile:
From neo4j:3.4
ENV NEO4J_AUTH=neo4j/password
COPY data.cypher /var/lib/neo4j/import/
USER neo4j
RUN bin/neo4j-admin set-initial-password password || true && \
bin/neo4j start && sleep 5 && \
cat /var/lib/neo4j/import/data.cypher | NEO4J_USERNAME=neo4j NEO4J_PASSWORD=password /var/lib/neo4j/bin/cypher-shell --fail-fast
CMD [neo4j]
I added also an match query to the data.cypher file to make sure that the shell added the data to neo4j. Maybe it has something to do that /data
is defined as volume in the neo4j image?
I was using Bierbarbar's approach. I got it working after getting over the following two pitfalls:
Firstly, $NEO4J_HOME/data
was symlinked to /data
, which seem to have permission issues. Changing the default data folder: by adding dbms.directories.data=mydata
line to $NEO4J_HOME/conf/neo4j.conf
fixed this.
Secondly, make sure data.cypher
file contains correct format for cypher-shell: 1) Semicolon is needed at the end of each cypher statemnt; 2) there are :begin
and :commit
commands in some versions (or all versions?) of cypher-shell
这篇关于使用来自cypher文件的初始数据创建自定义Neo4j Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!