dgraph 图数据库docker-compose安装试用
备注:
使用docker-compose进行安装
1. docker-compose.yml
version: "3"
services:
zero:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 5080:5080
- 6080:6080
restart: on-failure
command: dgraph zero --port_offset -2000 --my=zero:5080
server:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 8080:8080
- 9080:9080
restart: on-failure
command: dgraph server --my=server:7080 --memory_mb=2048 --zero=zero:5080
ratel:
image: dgraph/dgraph:latest
volumes:
- /tmp/data:/dgraph
ports:
- 8081:8081
command: dgraph-ratel
2. 启动
docker-compose up -d
3. 管理
浏览器打开http://ip:8081
按照提示输入连接的server http://ip:8080
4. 使用
a. 添加数据
curl localhost:8080/mutate -H "X-Dgraph-CommitNow: true" -XPOST -d $'
{
set {
_:luke <name> "Luke Skywalker" .
_:leia <name> "Princess Leia" .
_:han <name> "Han Solo" .
_:lucas <name> "George Lucas" .
_:irvin <name> "Irvin Kernshner" .
_:richard <name> "Richard Marquand" .
_:sw1 <name> "Star Wars: Episode IV - A New Hope" .
_:sw1 <release_date> "1977-05-25" .
_:sw1 <revenue> "775000000" .
_:sw1 <running_time> "121" .
_:sw1 <starring> _:luke .
_:sw1 <starring> _:leia .
_:sw1 <starring> _:han .
_:sw1 <director> _:lucas .
_:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
_:sw2 <release_date> "1980-05-21" .
_:sw2 <revenue> "534000000" .
_:sw2 <running_time> "124" .
_:sw2 <starring> _:luke .
_:sw2 <starring> _:leia .
_:sw2 <starring> _:han .
_:sw2 <director> _:irvin .
_:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
_:sw3 <release_date> "1983-05-25" .
_:sw3 <revenue> "572000000" .
_:sw3 <running_time> "131" .
_:sw3 <starring> _:luke .
_:sw3 <starring> _:leia .
_:sw3 <starring> _:han .
_:sw3 <director> _:richard .
_:st1 <name> "Star Trek: The Motion Picture" .
_:st1 <release_date> "1979-12-07" .
_:st1 <revenue> "139000000" .
_:st1 <running_time> "132" .
}
}
' | python -m json.tool | less
b. 查询(query)
curl localhost:8080/query -XPOST -d $'
{
me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
name
release_date
revenue
running_time
director {
name
}
starring {
name
}
}
}
' | python -m json.tool | less
4. 参考资料
https://docs.dgraph.io/get-started/#step-1-install-dgraph