2018-09-11 14:11:24 +03:00
|
|
|
Run Hasura GraphQL Engine using Docker
|
|
|
|
======================================
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2018-09-11 14:11:24 +03:00
|
|
|
This guide assumes that you already have Postgres running and helps you set up the Hasura GraphQL engine using Docker
|
|
|
|
and connect it to your Postgres database.
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Prerequisites
|
|
|
|
-------------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
- `Docker <https://docs.docker.com/install/>`_
|
|
|
|
|
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
Step 1: Get the **docker-run.sh** bash script
|
|
|
|
---------------------------------------------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
The `hasura/graphql-engine/install-manifests <https://github.com/hasura/graphql-engine/tree/master/install-manifests>`_
|
|
|
|
repo contains all installation manifests required to deploy Hasura anywhere.
|
2018-09-27 19:04:21 +03:00
|
|
|
|
|
|
|
Get the docker run bash script from there:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-09-13 12:33:13 +03:00
|
|
|
$ wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-run/docker-run.sh
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
Step 2: Configure the **docker-run.sh** script
|
|
|
|
----------------------------------------------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
The ``docker-run.sh`` script has a sample docker run command in it. The following changes have to be
|
2019-01-11 14:38:41 +03:00
|
|
|
made to the command:
|
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
- Database URL
|
|
|
|
- Network config
|
|
|
|
|
|
|
|
Database URL
|
2019-01-11 14:38:41 +03:00
|
|
|
^^^^^^^^^^^^
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2018-11-23 12:17:31 +03:00
|
|
|
Edit the ``HASURA_GRAPHQL_DATABASE_URL`` env var value, so that you can connect to your Postgres instance.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2018-11-23 12:17:31 +03:00
|
|
|
:emphasize-lines: 3
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
#! /bin/bash
|
|
|
|
docker run -d -p 8080:8080 \
|
2018-11-23 12:17:31 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \
|
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
|
|
|
hasura/graphql-engine:latest
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2018-11-23 12:17:31 +03:00
|
|
|
Examples of ``HASURA_GRAPHQL_DATABASE_URL``:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
- ``postgres://admin:password@localhost:5432/my-db``
|
|
|
|
- ``postgres://admin:@localhost:5432/my-db`` *(if there is no password)*
|
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. note::
|
|
|
|
|
2019-01-29 12:27:15 +03:00
|
|
|
- If your **password contains special characters** (e.g. #, %, $, @, etc.), you need to URL encode them in the
|
|
|
|
``HASURA_GRAPHQL_DATABASE_URL`` env var (e.g. %40 for @).
|
2019-01-11 14:38:41 +03:00
|
|
|
|
2019-01-29 12:27:15 +03:00
|
|
|
You can check the :doc:`logs <logging>` to see if the database credentials are proper and if Hasura is able
|
|
|
|
to connect to the database.
|
|
|
|
|
|
|
|
- Hasura GraphQL engine needs access permissions to your Postgres database as described in
|
|
|
|
:doc:`Postgres permissions <../postgres-permissions>`
|
2019-01-11 14:38:41 +03:00
|
|
|
|
|
|
|
Network config
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
If your Postgres instance is running on ``localhost`` the following changes will be needed to the ``docker run``
|
|
|
|
command to allow the Docker container to access the host's network:
|
|
|
|
|
|
|
|
.. rst-class:: api_tabs
|
|
|
|
.. tabs::
|
|
|
|
|
|
|
|
.. tab:: Linux
|
|
|
|
|
|
|
|
Add the ``--net=host`` flag to access the host's Postgres service.
|
|
|
|
|
|
|
|
This is what your command should look like:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. code-block:: bash
|
|
|
|
:emphasize-lines: 1
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
docker run -d --net=host \
|
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \
|
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
|
|
|
hasura/graphql-engine:latest
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. tab:: Docker for Mac
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
Use ``host.docker.internal`` as hostname to access the host's Postgres service.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
This is what your command should look like:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. code-block:: bash
|
|
|
|
:emphasize-lines: 2
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
docker run -d -p 8080:8080 \
|
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@host.docker.internal:port/dbname \
|
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
|
|
|
hasura/graphql-engine:latest
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. tab:: Docker for Windows
|
2018-11-23 12:17:31 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
Use ``docker.for.win.localhost`` as hostname to access the host's Postgres service.
|
2018-12-31 11:46:43 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
This is what your command should look like:
|
2018-12-31 11:46:43 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
.. code-block:: bash
|
|
|
|
:emphasize-lines: 2
|
2018-12-31 11:46:43 +03:00
|
|
|
|
2019-01-11 14:38:41 +03:00
|
|
|
docker run -d -p 8080:8080 \
|
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@docker.for.win.localhost:port/dbname \
|
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
|
|
|
hasura/graphql-engine:latest
|
2018-12-31 11:46:43 +03:00
|
|
|
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
Step 3: Run the Hasura docker container
|
2018-09-27 19:04:21 +03:00
|
|
|
---------------------------------------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2018-09-12 12:28:55 +03:00
|
|
|
Execute ``docker-run.sh`` & check if everything is running well:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-09-12 12:28:55 +03:00
|
|
|
$ ./docker-run.sh
|
2018-09-11 14:11:24 +03:00
|
|
|
$ docker ps
|
|
|
|
|
2018-10-10 17:21:43 +03:00
|
|
|
CONTAINER ID IMAGE ... CREATED STATUS PORTS ...
|
|
|
|
097f58433a2b hasura/graphql-engine.. ... 1m ago Up 1m 8080->8080/tcp ...
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
Step 4: Open the Hasura console
|
2018-09-11 14:11:24 +03:00
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
Head to http://localhost:8080/console to open the Hasura console.
|
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
Step 5: Track existing tables and relationships
|
2018-09-11 14:11:24 +03:00
|
|
|
-----------------------------------------------
|
|
|
|
|
2018-10-10 17:21:43 +03:00
|
|
|
See :doc:`../../schema/using-existing-database` to enable GraphQL over the database.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Advanced
|
|
|
|
--------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
- :doc:`Securing your GraphQL endpoint <securing-graphql-endpoint>`
|
2018-10-10 17:21:43 +03:00
|
|
|
- :doc:`GraphQL engine server logs <logging>`
|
2018-09-11 14:11:24 +03:00
|
|
|
- :doc:`Updating GraphQL engine <updating>`
|
|
|
|
- :doc:`Setting up migrations <../../migrations/index>`
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:titlesonly:
|
|
|
|
:hidden:
|
|
|
|
|
|
|
|
Securing your GraphQL endpoint <securing-graphql-endpoint>
|
2018-10-10 17:21:43 +03:00
|
|
|
GraphQL engine server logs <logging>
|
2018-09-11 14:11:24 +03:00
|
|
|
Updating GraphQL engine <updating>
|