我之前在Windows上安装了neo4j,并运行了PowerShell脚本来运行一些迁移。每次从导入文件夹中的这些迁移脚本和某些CSV重新创建数据库。 .NET WebAPI与neo4j db进行通信。
我决定Dockerize这个设置,以便我可以与人们进行跨平台协作,他们不必直接安装/配置neo4j。
我已经设置了大部分neo4j docker容器 - 卷,适当的文件复制等等,它启动了。
无论如何,我似乎找不到插入或执行将循环遍历文件夹并执行密码查询的脚本的好方法。我知道这可能是一个使用neo4j CLI的bash脚本,我对此很好,但我找不到一个让它成为现实的好地方。
EXTENSION_SCRIPT
env变量。这在过程中过早地执行。ENTRYPOINT
- 发现这似乎取代了neo4j容器的入口点CMD
- 同样,这似乎取代了docker-compose
移动到dockerfile
并复制neo4j入口点文件进行修改。这似乎遇到了一个问题invalid optionn/bash: -
,我正在研究过程中,但这是我的第一件事。在Neo4j启动后如何运行一个或多个密码查询?在neo4j或docker中是否有规定允许这样做?我无法在文档中找到任何线索。
或者,这真的不是推荐的方式吗?我是否应该通过输入容器并手动运行与CLI一起使用的bash脚本来按需运行这些迁移?
Dockerfile:
FROM neo4j:3.3.1
COPY ./data/import/migrations/scripts /scripts
ENV NEO4J_AUTH=none
ENTRYPOINT ["/scripts/docker-neo4j-entrypoint.sh"]
CMD ["neo4j"]
来自docker-compose
的相关片段:
neo4j:
container_name: 'app-db'
build:
context: .
dockerfile: DOCKERFILE_DB
volumes:
- ./data/CSVs:/import
- ./data/import/migrations:/import/migrations
ports:
- "7687:7687" # bolt protocol
- "7474:7474" # http protocol
- "7473:7473" # https protocol
networks:
- app-network
我遇到了同样的问题,我想在启动时创建一些索引,并且能够根据文档here解决它以创建包装器脚本,以及直到neo4j备份的索引脚本,如下所示:
Dockerfile
FROM neo4j:latest
ENV NEO4J_AUTH=neo4j/password
RUN apk add --no-cache --quiet procps
COPY create-indexes.sh create-indexes.sh
COPY wrapper.sh wrapper.sh
ENTRYPOINT ["./wrapper.sh"]
wrapper.是:
#!/bin/bash
# turn on bash's job control
set -m
# Start the primary process and put it in the background
/docker-entrypoint.sh neo4j &
# Start the helper process
./create-indexes.sh
# the my_helper_process might need to know how to wait on the
# primary process to start before it does its work and returns
# now we bring the primary process back into the foreground
# and leave it there
fg %1
create-indexes.是
#!/bin/bash
until cypher-shell -u neo4j -p shaun123 'CREATE INDEX ON :Page(url);'
do
echo "create page index failed, sleeping"
sleep 10
done
until cypher-shell -u neo4j -p shaun123 'CREATE INDEX ON :Visited(url);'
do
echo "create visited index failed, sleeping"
sleep 10
done
until cypher-shell -u neo4j -p shaun123 'CREATE INDEX ON :Anchor(url);'
do
echo "create anchor index failed, sleeping"
sleep 10
done
我也打开了这个问题here,我把我的答案复制到了关闭之后。