目录
1 docker拉取neo4j镜像
(1)从景下源中找到合适的镜像
命令:docker search neo4j
(2)拉取镜像源
命令:docker pull neo4j:版本号
2 构建neo4j容器
命令:docker run --name qa_poi_container -d -it -p 7474:7474 -p 7687:7687 --mount type=bind,source=/home/neo4j/conf,target=/var/lib/neo4j/conf --mount type=bind,source=/home/neo4j/logs,target=/var/lib/neo4j/logs --mount type=bind,source=/home/neo4j/import,target=/var/lib/neo4j/import --mount type=bind,source=/home/neo4j/data,target=/var/lib/neo4j/data neo4j:latest /bin/bash
user@jd:~$ docker run --name qa_poi_container -d -it -p 7474:7474 -p 7687:7687 --mount type=bind,source=/home/neo4j/conf,target=/var/lib/neo4j/conf --mount type=bind,source=/home/neo4j/logs,target=/var/lib/neo4j/logs --mount type=bind,source=/home/neo4j/import,target=/var/lib/neo4j/import --mount type=bind,source=/home/neo4j/data,target=/var/lib/neo4j/data neo4j:latest /bin/bash
3 进入容器修改文件夹权限
命令:docker exec -it qa_poi_container /bin/bash
然后输入命令:
root@3b9ed8eec679:/var/lib/neo4j# ls
LICENSE.txt NOTICE.txt UPGRADE.txt certificates data labs logs run
LICENSES.txt README.txt bin conf import lib plugins
root@3b9ed8eec679:/var/lib/neo4j#
root@3b9ed8eec679:/var/lib/neo4j# chmod 777 -R conf
root@3b9ed8eec679:/var/lib/neo4j# chmod 777 -R data
root@3b9ed8eec679:/var/lib/neo4j# chmod 777 -R logs
root@3b9ed8eec679:/var/lib/neo4j# chmod 777 -R import
root@3b9ed8eec679:/var/lib/neo4j# ls -l
total 264
-rwxrwxrwx 1 neo4j neo4j 36005 Nov 23 18:30 LICENSE.txt
-rwxrwxrwx 1 neo4j neo4j 152530 Nov 23 18:30 LICENSES.txt
-rwxrwxrwx 1 neo4j neo4j 9170 Nov 23 18:30 NOTICE.txt
-rwxrwxrwx 1 neo4j neo4j 1399 Nov 23 18:30 README.txt
-rwxrwxrwx 1 neo4j neo4j 96 Nov 23 18:30 UPGRADE.txt
drwx------ 1 neo4j neo4j 4096 Nov 23 18:46 bin
drwx------ 1 neo4j neo4j 4096 Nov 23 18:30 certificates
drwxrwxrwx 2 neo4j neo4j 4096 Jan 6 09:54 conf
lrwxrwxrwx 1 neo4j neo4j 5 Dec 12 02:44 data -> /data
drwxrwxrwx 2 neo4j neo4j 4096 Jan 4 09:39 import
drwx------ 1 neo4j neo4j 4096 Dec 12 02:44 labs
drwx------ 1 neo4j neo4j 12288 Dec 12 02:44 lib
lrwxrwxrwx 1 neo4j neo4j 5 Dec 12 02:44 logs -> /logs
drwx------ 1 neo4j neo4j 4096 Dec 12 02:44 plugins
drwx------ 1 neo4j neo4j 4096 Jan 6 09:42 run
注意:现在不要在这里启动neo4j,如果在这里启动会造成文件被匿名进程锁死问题。
4 进入容器
启动neo4j之前保持挂载的文件夹data干净
命令:docker attach qa_poi_container
user@jd:~$ docker attach qa_poi_container
neo4j@3b9ed8eec679:~$ ls
LICENSE.txt NOTICE.txt UPGRADE.txt certificates data labs logs run
LICENSES.txt README.txt bin conf import lib plugins
neo4j@3b9ed8eec679:~$
5 修改配置文件
配置文件:/conf/neo4j.conf
neo4j@3b9ed8eec679:~$ cat conf/neo4j.conf
dbms.default_database=poitest.db
dbms.default_listen_address=0.0.0.0
dbms.memory.pagecache.size=512M
dbms.default_advertised_address=10.XX.XX.21
dbms.connector.bolt.enabled=true
dbms.connector.bolt.listen_address=:7687
dbms.connector.bolt.advertised_address=10.xx.xx.21
dbms.connector.http.listen_address=:7474
dbms.connector.http.advertised_address=10.xx.xx.21
neo4j@3b9ed8eec679:~$
6 将数据导入到neo4j数据库中
将csv文件放入import文件夹中
neo4j@3b9ed8eec679:~$ ls
LICENSE.txt NOTICE.txt UPGRADE.txt certificates data labs logs run
LICENSES.txt README.txt bin conf import lib plugins
neo4j@3b9ed8eec679:~$ pwd
/var/lib/neo4j
neo4j@3b9ed8eec679:~$ cd import/
neo4j@3b9ed8eec679:~/import$ ls
import.report relation_abstract_transport_2_metro_station.csv
nodes_abstract_transport.csv relation_abstract_type_2_type.csv
nodes_abstract_type.csv relation_father_type_2_sub_type.csv
nodes_metro_station.csv relation_poi_2_abstract_transport.csv
nodes_poi.csv relation_poi_2_abstract_type.csv
nodes_poi_type.csv
neo4j@3b9ed8eec679:~/import$ neo4j-admin import --database=poitest.db --nodes=nodes_poi.csv --nodes='nodes_abstract_transport.csv' --nodes='nodes_abstract_type.csv' --nodes='nodes_metro_station.csv' --nodes='nodes_poi_type.csv' --relationships 'relation_abstract_transport_2_metro_station.csv' --relationships 'relation_abstract_type_2_type.csv' --relationships 'relation_father_type_2_sub_type.csv' --relationships 'relation_poi_2_abstract_transport.csv' --relationships 'relation_poi_2_abstract_type.csv'
csv数据格式:
节点数据:
关系数据:
7 启动neo4j
8 重启容器
退出attach容器时,容器会停止运行
重启容器:
此时neo4j仍没有运行:
9 exec方式进入容器重启neo4j
这样后台neo4j程序就能一直运行:
10 参考文章
https://www.cnblogs.com/caoyusang/p/13610408.html