Quickstart with Docker

Introduction

This guide will help you get the Hasura GraphQL engine and Postgres running as Docker containers using Docker Compose. This is the easiest way to set up Hasura GraphQL engine on your local environment.

In case you’d like to run Hasura on an existing Postgres database, follow this guide to deploy the Hasura GraphQL engine as a standalone docker container and connect it to your Postgres instance.

Prerequisites

Step 1: Get the docker-compose file

The hasura/graphql-engine/install-manifests repo contains all installation manifests required to deploy Hasura anywhere. Get the docker compose file from there:

# in a new directory run
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
# or run
curl https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml -o docker-compose.yml

Try out Hasura v2.0

You can try out the latest alpha release of Hasura v2.0 by using the following manifests instead:

# 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

See the changelog

Step 2: Run Hasura GraphQL engine & Postgres

$ docker-compose up -d

Check if the containers are running:

$ 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

Head to http://localhost:8080/console to open the Hasura console.

Step 4: Try out Hasura

Create a table

On the Hasura console, navigate to Data -> Create table and create a sample table called profiles with the following columns:

profiles (
  id SERIAL PRIMARY KEY, -- serial -> auto-incrementing integer
  name TEXT
)
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:

query {
  profiles {
    id
    name
  }
}

You’ll see that you get all the inserted data!

Try out a query

Next steps

Learn course

For a full hands-on tour of Hasura, check out our 30-Minute Hasura Basics Course.

Database operations

  • Database modelling: Learn how to model your database schema, as well as how to extend it.
  • Querying data: Use GraphQL queries to query data from your GraphQL API.
  • Inserting data: 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.

  • Actions: Actions can be used if you’d like to extend your GraphQL schema by integrating with a REST endpoint.
  • Remote schemas: If you have an existing GraphQL server or if you’re comfortable with implementing one, you can use remote schemas.
  • Event triggers: To trigger a serverless function based on a database event, use event triggers.
  • Scheduled triggers: Scheduled triggers are used to execute custom business logic at specific points in time.

Migrations

Set up Hasura migrations 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

Add an admin secret to make sure that your GraphQL endpoint and the Hasura console are not publicly accessible.

Advanced Docker setup

This was a quickstart guide to get the Hasura GraphQL engine up and running quickly. For more detailed instructions on deploying using Docker with an external database, check out Run Hasura GraphQL engine using Docker.

  • Using Docker: Run as a docker container and connect to an existing Postgres database.