Newer
Older
+++
title = "Get Started"
+++
## Dgraph
Dgraph cluster consists of different nodes (zero, server & ratel) and each node serves a different purpose.
**Dgraph Zero** controls the Dgraph cluster, assigns servers to a group and re-balances data between server groups.
**Dgraph Server** hosts predicates and indexes.
**Dgraph Ratel** serves the UI to run queries, mutations & altering schema.
You need atleast need one Dgraph zero and one Dgraph Server to get started.
**Here's a 3 step tutorial to get you up and running.**
This is a quick-start guide to running Dgraph. For an interactive walk through, take the [tour](https://tour.dgraph.io).
You can see the accompanying [video here](https://www.youtube.com/watch?v=QIIdSp2zLcs).
Dgraph can be installed from the install scripts, or run via Docker.
{{% notice "note" %}}These instructions will install the latest release version. To instead install our nightly build see [these instructions](/deploy).{{% /notice %}}
### From Docker Image
Pull the Dgraph Docker images [from here](https://hub.docker.com/r/dgraph/dgraph/). From a terminal:
```sh
docker pull dgraph/dgraph
```
### From Install Scripts (Linux/Mac)
```
The script automatically installs Dgraph. Once done, jump straight to [step 2]({{< relref "#step-2-run-dgraph" >}}).
**Alternative:** To mitigate potential security risks, instead try:
curl https://get.dgraph.io > /tmp/get.sh
vim /tmp/get.sh # Inspect the script
sh /tmp/get.sh # Execute the script
```
You can check that Dgraph binary installed correctly by running `dgraph` and
looking at its output, which includes the version number.
### Installing on Windows
{{% notice "note" %}}Binaries for Windows are available from `v0.8.3`.{{% /notice %}}
If you wish to install the binaries on Windows, you can get them from the [Github releases](https://github.com/dgraph-io/dgraph/releases), extract and install them manually. The file `dgraph-windows-amd64-v1.x.y.tar.gz` contains the dgraph binary.
{{% notice "note" %}} This is a set up involving just one machine. For multi-server setup, go to [Deploy](/deploy). {{% /notice %}}
### Docker Compose
The easiest way to get Dgraph up and running is using Docker Compose. Follow the instructions
[here](https://docs.docker.com/compose/install/) to install Docker Compose if you don't have it
already.
```
services:
zero:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
- 6080:6080
restart: on-failure
command: dgraph zero --my=zero:5080
server:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
ports:
- 8080:8080
- 9080:9080
restart: on-failure
Pawan Rawal
committed
command: dgraph server --my=server:7080 --lru_mb=2048 --zero=zero:5080
ratel:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
command: dgraph-ratel
```
Save the contents of the snippet above in a file called `docker-compose.yml`, then run the following
command from the folder containing the file.
```
docker-compose up -d
```
This would start Dgraph Server, Zero and Ratel. You can check the logs using `docker-compose logs`
**Run Dgraph zero**
Run `dgraph zero` to start Dgraph zero. This process controls Dgraph cluster,
maintaining membership information, shard assignment and shard movement, etc.
Run `dgraph server` to start Dgraph server.
Pawan Rawal
committed
dgraph server --lru_mb 2048 --zero localhost:5080
```
Run 'dgraph-ratel' to start Dgraph UI. This can be used to do mutations and query through UI.
Pawan Rawal
committed
{{% notice "tip" %}}You need to set the estimated memory Dgraph server can take through `lru_mb` flag. This is just a hint to the Dgraph server and actual usage would be higher than this. It's recommended to set lru_mb to one-third the available RAM.{{% /notice %}}
# Directory to store data in. This would be passed to `-v` flag.
mkdir -p /tmp/data
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v /tmp/data:/dgraph --name diggy dgraph/dgraph dgraph zero
Pawan Rawal
committed
docker exec -it diggy dgraph server --lru_mb 2048 --zero localhost:5080
```
The dgraph server listens on ports 8080 and 9080 with log output to the terminal.
File access in mounted filesystems is slower when using docker. Try running the command `time dd if=/dev/zero of=test.dat bs=1024 count=100000` on mounted volume and you will notice that it's horribly slow when using mounted volumes. We recommend users to use docker data volumes. The only downside of using data volumes is that you can't access the files from the host, you have to launch a container for accessing it.
{{% notice "tip" %}}If you are using docker on non-linux distribution, please use docker data volumes.{{% /notice %}}
Create a docker data container named *data* with dgraph/dgraph image.
docker create -v /dgraph --name data dgraph/dgraph
Now if we run Dgraph container with `--volumes-from` flag and run Dgraph with the following command, then anything we write to /dgraph in Dgraph container will get written to /dgraph volume of datacontainer.
docker run -it -p 5080:5080 -p 6080:6080 --volumes-from data --name diggy dgraph/dgraph dgraph zero
Pawan Rawal
committed
docker exec -it diggy dgraph server --lru_mb 2048 --zero localhost:5080
# Run Dgraph Ratel
docker exec -it diggy dgraph-ratel
{{% notice "tip" %}}
If you are using Dgraph v1.0.2 (or older) then the default ports are 7080, 8080 for zero, so when following instructions for different setup guides override zero port using `--port_offset`.
```sh
Pawan Rawal
committed
dgraph zero --lru_mb=<typically one-third the RAM> --port_offset -2000
```
Ratel's default port is 8081, so override it using -p 8000.
{{% /notice %}}
{{% notice "tip" %}}Once Dgraph is running, you can access Ratel at [`http://localhost:8000`](http://localhost:8000). It allows browser-based queries, mutations and visualizations.
The mutations and queries below can either be run from the command line using `curl localhost:8080/query -XPOST -d $'...'` or by pasting everything between the two `'` into the running user interface on localhost.{{% /notice %}}
The dataset is a movie graph, where and the graph nodes are entities of the type directors, actors, genres, or movies.
### Storing data in the graph
Changing the data stored in Dgraph is a mutation. The following mutation stores information about the first three releases of the the ''Star Wars'' series and one of the ''Star Trek'' movies. Running this mutation, either through the UI or on the command line, will store the data in Dgraph.
curl localhost:8080/mutate -H "X-Dgraph-CommitNow: true" -XPOST -d $'
{
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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" .
}
Alter the schema to add indexes on some of the data so queries can use term matching, filtering and sorting.
curl localhost:8080/alter -XPOST -d $'
name: string @index(term) .
release_date: datetime @index(year) .
revenue: float .
running_time: int .
```
Run this query to get all the movies. The query works below all the movies have a starring edge
```sh
curl localhost:8080/query -XPOST -d $'
{
me(func: has(starring)) {
name@en
}
}
' | python -m json.tool | less
```
### Get all movies released after "1980"
Run this query to get "Star Wars" movies released after "1980". Try it in the user interface to see the result as a graph.
me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
name
release_date
revenue
running_time
director {
name
}
starring {
name
}
}
```
{
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
"data":{
"me":[
{
"name":"Star Wars: Episode V - The Empire Strikes Back",
"release_date":"1980-05-21T00:00:00Z",
"revenue":534000000.0,
"running_time":124,
"director":[
{
"name":"Irvin Kernshner"
}
],
"starring":[
{
"name":"Han Solo"
},
{
"name":"Luke Skywalker"
},
{
"name":"Princess Leia"
}
]
},
{
"name":"Star Wars: Episode VI - Return of the Jedi",
"release_date":"1983-05-25T00:00:00Z",
"revenue":572000000.0,
"running_time":131,
"director":[
{
"name":"Richard Marquand"
}
],
"starring":[
{
"name":"Han Solo"
},
{
"name":"Luke Skywalker"
},
{
"name":"Princess Leia"
}
]
}
]
}
```
That's it! In these three steps, we set up Dgraph, added some data, set a schema
and queried that data back.
- Go to [Clients]({{< relref "clients/index.md" >}}) to see how to communicate
with Dgraph from your application.
- Take the [Tour](https://tour.dgraph.io) for a guided tour of how to write queries in Dgraph.
- A wider range of queries can also be found in the [Query Language](/query-language) reference.
- See [Deploy](/deploy) if you wish to run Dgraph
## Need Help
* Please use [discuss.dgraph.io](https://discuss.dgraph.io) for questions, feature requests and discussions.
* Please use [Github Issues](https://github.com/dgraph-io/dgraph/issues) if you encounter bugs or have feature requests.
* You can also join our [Slack channel](http://slack.dgraph.io).
## Troubleshooting
### 1. Docker: Error response from daemon; Conflict. Container name already exists.
Remove the diggy container and try the docker run command again.