Neo4j docker deployment

If you want to run a simple test of neo4j, you can directly use docker to create a container, connect to neo4j locally with cypher-shell, and create a graph for testing.

1 start docker

sudo systemctl start docker

2 Pull the image source

sudo docker pull neo4j # 默认latest版本

3 Check the local mirror to check whether the pull is successful

sudo docker images

4 Create a container and run it

Create four directories of data, logs, conf, and import in the /home/neo4j directory

  • data, the folder where the data is stored
  • logs, the running log folder
  • conf, the database configuration folder
  • import, in order to import csv in large quantities to build a database, only files in .csv format can be imported, which should be placed in this folder
sudo docker run -d --name container_name -p 27474:7474 -p 27687:7687 -v /home/neo4j/data:/data -v /home/neo4j/logs:/logs -v /home/neo4j/conf:/var/lib/neo4j/conf -v /home/neo4j/import:/var/lib/neo4j/import --env NEO4J_AUTH=neo4j/password neo4j
-d --name container_name   //-d表示容器后台运行 --name指定容器名字
-p 27474:7474 -p 27687:7687   //映射容器的端口号到宿主机的端口号;27474 为宿主机端口
-v /home/neo4j/data:/data   //把容器内的数据目录挂载到宿主机的对应目录下
-v /home/neo4j/logs:/logs   //挂载日志目录
-v /home/neo4j/conf:/var/lib/neo4j/conf   //挂载配置目录
-v /home/neo4j/import:/var/lib/neo4j/import   //挂载数据导入目录
--env NEO4J_AUTH=neo4j/password   //设定数据库的名字的访问密码
neo4j //指定使用的镜像

5 Check whether the container is built successfully

sudo docker ps -a

6 Access to the interior of the container

sudo docker exec -it 容器id bash
# 例如:sudo docker exec -it ea6ecd2e43ac bash

7 Run the client cypher-shell

./bin/cypher-shell

8 Cypher graph creation, graph query

neo4j@neo4j> CREATE (node1:Router {
    
    ip:'127.0.0.1'}),(node2:Router {
    
    ip:'127.0.0.2'}),(node3:Router {
    
    ip:'127.0.0.3'}),(node4:Router {
    
    ip:'127.0.0.4'}),(node5:Router {
    
    ip:'127.0.0.5'}),(node6:Router {
    
    ip:'127.0.0.6'}),(node7:Router {
    
    ip:'127.0.0.7'}),(node8:Router {
    
    ip:'127.0.0.8'}),(node9:Router {
    
    ip:'127.0.0.9'}),(node1)-[:Connect]->(node4),(node2)-[:Connect]->(node5),(node3)-[:Connect]->(node6),(node4)-[:Connect]->(node7),(node4)-[:Connect]->(node8),(node5)-[:Connect]->(node8),(node6)-[:Connect]->(node9);
0 rows
ready to start consuming query after 412 ms, results consumed after another 0 ms
Added 9 nodes, Created 7 relationships, Set 9 properties, Added 9 labels
neo4j@neo4j>
neo4j@neo4j>
neo4j@neo4j> MATCH (r:Router)-[:Connect]->(t:Router)-[:Connect]->(p:Router) WHERE r.ip >= '127.0.0.1' AND r.ip <= '127.0.0.3' RETURN t.ip, p.ip
             ;
+---------------------------+
| t.ip        | p.ip        |
+---------------------------+
| "127.0.0.4" | "127.0.0.8" |
| "127.0.0.4" | "127.0.0.7" |
| "127.0.0.5" | "127.0.0.8" |
| "127.0.0.6" | "127.0.0.9" |
+---------------------------+

4 rows
ready to start consuming query after 422 ms, results consumed after another 12 ms

9 Exit cypher-shell and container

:exit # 退出cypher-shell
exit # 退出容器

10 Container stopped running

sudo docker stop 容器id

Guess you like

Origin blog.csdn.net/qq_49588762/article/details/131563625