2020-01-14 15:57:45 +03:00
.. meta ::
:description: Get started with Hasura using Docker
:keywords: hasura, docs, start, docker
2020-03-11 22:42:36 +03:00
.. _docker_simple:
2018-09-11 14:11:24 +03:00
Quickstart with Docker
======================
2018-12-03 15:12:24 +03:00
.. contents :: Table of contents
:backlinks: none
:depth: 1
:local:
2020-07-31 18:26:55 +03:00
Introduction
------------
2019-09-11 10:17:14 +03:00
This guide will help you get the Hasura GraphQL engine and Postgres running as
2018-10-19 19:59:18 +03:00
Docker containers using Docker Compose. This is the easiest way to set up
2018-09-11 14:11:24 +03:00
Hasura GraphQL engine on your **local environment** .
2020-07-31 18:26:55 +03:00
In case you'd like to run Hasura on an existing Postgres database, follow :ref: `this guide <deployment_docker>`
to deploy the Hasura GraphQL engine as a standalone docker container and connect it to your Postgres instance.
2018-09-11 14:11:24 +03:00
2018-12-03 15:12:24 +03:00
Prerequisites
-------------
2018-09-11 14:11:24 +03:00
2021-02-18 14:33:15 +03:00
- `Docker <https://docs.docker.com/install/> `__
- `Docker Compose <https://docs.docker.com/compose/install/> `__
2018-09-11 14:11:24 +03:00
Step 1: Get the docker-compose file
2020-02-19 14:43:08 +03:00
-----------------------------------
2018-09-11 14:11:24 +03:00
2020-07-09 11:42:33 +03:00
The `hasura/graphql-engine/install-manifests <https://github.com/hasura/graphql-engine/tree/stable/install-manifests> `__ repo
2018-09-11 14:11:24 +03:00
contains all installation manifests required to deploy Hasura anywhere. Get the docker compose file from there:
.. code-block :: bash
2020-06-24 10:15:33 +03:00
# in a new directory run
2020-02-19 14:43:08 +03:00
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
2020-06-24 10:15:33 +03:00
# or run
curl https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml -o docker-compose.yml
2018-09-11 14:11:24 +03:00
2021-02-23 17:38:06 +03:00
.. admonition :: Try out Hasura v2.0
You can try out the latest alpha release of Hasura v2.0 by using the following manifests instead:
.. code-block :: bash
# in a new directory run
wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-compose-v2.0.0/docker-compose.yaml
# or run
curl https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-compose-v2.0.0/docker-compose.yaml -o docker-compose.yml
2021-02-24 15:38:39 +03:00
See the `changelog <https://github.com/hasura/graphql-engine/releases> `__
2021-02-23 17:38:06 +03:00
2018-09-11 14:11:24 +03:00
Step 2: Run Hasura GraphQL engine & Postgres
--------------------------------------------
.. code-block :: bash
$ docker-compose up -d
Check if the containers are running:
.. code-block :: bash
$ docker ps
CONTAINER ID IMAGE ... CREATED STATUS PORTS ...
097f58433a2b hasura/graphql-engine ... 1m ago Up 1m 8080->8080/tcp ...
b0b1aac0508d postgres ... 1m ago Up 1m 5432/tcp ...
Step 3: Open the Hasura console
-------------------------------
2018-10-19 19:59:18 +03:00
Head to `` http://localhost:8080/console `` to open the Hasura console.
2018-09-11 14:11:24 +03:00
2021-02-18 14:33:15 +03:00
Step 4: Try out Hasura
2020-09-10 12:32:57 +03:00
----------------------
2018-09-11 14:11:24 +03:00
2021-02-18 14:33:15 +03:00
Create a table
^^^^^^^^^^^^^^
2018-09-11 14:11:24 +03:00
2021-02-18 14:33:15 +03:00
On the Hasura console, navigate to `` Data -> Create table `` and create a sample table called `` profiles `` with
the following columns:
2018-09-11 14:11:24 +03:00
2021-02-18 14:33:15 +03:00
.. code-block :: sql
profiles (
id SERIAL PRIMARY KEY, -- serial -> auto-incrementing integer
name TEXT
)
.. thumbnail :: /img/graphql/core/getting-started/create-profile-table.png
:alt: Create a table
Now, insert some sample data into the table using the `` Insert Row `` tab of the `` profiles `` table.
Try out a query
^^^^^^^^^^^^^^^
Head to the `` GraphiQL `` tab in the console and try running the following query:
.. code-block :: graphql
query {
profiles {
id
name
}
}
You'll see that you get all the inserted data!
.. thumbnail :: /img/graphql/core/getting-started/profile-query.png
:alt: Try out a query
Next steps
----------
Learn course
^^^^^^^^^^^^
For a full hands-on tour of Hasura, check out our `30-Minute Hasura Basics Course <https://hasura.io/learn/graphql/hasura/introduction/> `__ .
Database operations
^^^^^^^^^^^^^^^^^^^
- :ref: `Database modelling <schema>` : Learn how to model your database schema, as well as how to extend it.
- :ref: `Querying data <queries>` : Use GraphQL queries to query data from your GraphQL API.
- :ref: `Inserting data <mutations>` : Use GraphQL mutations to insert data into your GraphQL API.
Business logic
^^^^^^^^^^^^^^
There are several options for the implementation of business logic, depending on your use case.
- :ref: `Actions <actions>` : Actions can be used if you'd like to extend your GraphQL schema by integrating with a REST endpoint.
- :ref: `Remote schemas <remote_schemas>` : If you have an existing GraphQL server or if you're comfortable with implementing one, you can use remote schemas.
- :ref: `Event triggers <event_triggers>` : To trigger a serverless function based on a database event, use event triggers.
- :ref: `Scheduled triggers <scheduled_triggers>` : Scheduled triggers are used to execute custom business logic at specific points in time.
Migrations
^^^^^^^^^^
Set up :ref: `Hasura migrations <migrations_setup>` to track your database alterations. This will make it easier to move to a different environment (e.g. staging or prod) later.
Secure your endpoint
^^^^^^^^^^^^^^^^^^^^
:ref: `Add an admin secret <secure_project>`
to make sure that your GraphQL endpoint and the Hasura console are not publicly accessible.
Advanced Docker setup
---------------------
2018-09-11 14:11:24 +03:00
This was a quickstart guide to get the Hasura GraphQL engine up and running
2020-09-08 23:14:36 +03:00
quickly. For more detailed instructions on deploying using Docker with an
external database, check out :ref: `deployment_docker` .
2021-02-18 14:33:15 +03:00
- :ref: `Using Docker <deployment_docker>` : Run as a docker container and connect to an existing Postgres
database.