2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Deploy Hasura GraphQL engine with Docker
|
|
|
|
:keywords: hasura, docs, deployment, docker
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
.. _deployment_docker:
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
Run Hasura GraphQL engine using Docker
|
2018-09-11 14:11:24 +03:00
|
|
|
======================================
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2020-07-23 15:34:17 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
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.
|
|
|
|
|
2020-07-31 18:26:55 +03:00
|
|
|
In case you'd like to run Hasura with a fresh Postgres database, follow :ref:`this guide <docker_simple>`
|
|
|
|
to deploy the Hasura GraphQL engine along with a Postgres instance using Docker Compose.
|
|
|
|
|
2020-07-23 15:34:17 +03:00
|
|
|
Deploying Hasura using Docker
|
|
|
|
-----------------------------
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Prerequisites
|
2020-07-23 15:34:17 +03:00
|
|
|
^^^^^^^^^^^^^
|
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
|
2020-07-23 15:34:17 +03:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-02-19 14:43:08 +03:00
|
|
|
The `hasura/graphql-engine/install-manifests <https://github.com/hasura/graphql-engine/tree/stable/install-manifests>`_
|
2019-03-06 11:58:04 +03:00
|
|
|
repo contains all installation manifests required to deploy Hasura anywhere.
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
Get the Docker run bash script from there:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2020-02-19 14:43:08 +03:00
|
|
|
$ wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/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
|
2020-07-23 15:34:17 +03:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-09-11 10:17:14 +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
|
2020-07-23 15:34:17 +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 \
|
2021-01-11 22:20:38 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://<username>:<password>@hostname:<port>/<dbname> \
|
2018-11-23 12:17:31 +03:00
|
|
|
-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
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
You can check the :ref:`logs <docker_logs>` to see if the database credentials are proper and if Hasura is able
|
2019-01-29 12:27:15 +03:00
|
|
|
to connect to the database.
|
|
|
|
|
|
|
|
- Hasura GraphQL engine needs access permissions to your Postgres database as described in
|
2020-03-11 22:42:36 +03:00
|
|
|
:ref:`Postgres permissions <postgres_permissions>`.
|
2019-01-11 14:38:41 +03:00
|
|
|
|
|
|
|
Network config
|
2020-07-23 15:34:17 +03:00
|
|
|
**************
|
2019-01-11 14:38:41 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
If your Postgres instance is running on ``localhost``, the following changes will be needed to the ``docker run``
|
2019-01-11 14:38:41 +03:00
|
|
|
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 \
|
2021-01-11 22:20:38 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://<username>:<password>@hostname:<port>/<dbname> \
|
2019-01-11 14:38:41 +03:00
|
|
|
-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 \
|
2021-01-11 22:20:38 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://<username>:<password>@host.docker.internal:<port>/<dbname> \
|
2019-01-11 14:38:41 +03:00
|
|
|
-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
|
|
|
|
2021-05-07 16:01:32 +03:00
|
|
|
Use ``host.docker.internal`` 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 \
|
2021-05-07 16:01:32 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://<username>:<password>@host.docker.internal:<port>/<dbname> \
|
2019-01-11 14:38:41 +03:00
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
|
|
|
hasura/graphql-engine:latest
|
2021-05-07 16:01:32 +03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
In earlier Docker for Windows versions the hostname used to be ``docker.for.win.localhost``
|
2018-12-31 11:46:43 +03:00
|
|
|
|
2018-09-27 19:04:21 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
Step 3: Run the Hasura Docker container
|
2020-07-23 15:34:17 +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
|
2020-07-23 15:34:17 +03:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2021-03-02 12:26:16 +03:00
|
|
|
Head to ``http://localhost:8080/console`` to open the Hasura console.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2019-03-06 11:58:04 +03:00
|
|
|
Step 5: Track existing tables and relationships
|
2020-07-23 15:34:17 +03:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
See :ref:`schema_existing_db` to enable GraphQL over the database.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-07-23 15:34:17 +03:00
|
|
|
.. _docker_secure:
|
|
|
|
|
|
|
|
Securing the GraphQL endpoint
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
To make sure that your GraphQL endpoint and the Hasura console are not publicly accessible, you need to
|
|
|
|
configure an admin secret key.
|
|
|
|
|
|
|
|
Run the Docker command with an admin-secret env var
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
:emphasize-lines: 5
|
|
|
|
|
|
|
|
#! /bin/bash
|
|
|
|
docker run -d -p 8080:8080 \
|
2021-01-11 22:20:38 +03:00
|
|
|
-e HASURA_GRAPHQL_DATABASE_URL=postgres://<username>:<password>@hostname:<port>/<dbname> \
|
2020-07-23 15:34:17 +03:00
|
|
|
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
|
2021-01-11 22:20:38 +03:00
|
|
|
-e HASURA_GRAPHQL_ADMIN_SECRET=<myadminsecretkey> \
|
2020-07-23 15:34:17 +03:00
|
|
|
hasura/graphql-engine:latest
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The ``HASURA_GRAPHQL_ADMIN_SECRET`` should never be passed from the client to the Hasura GraphQL engine as it would
|
|
|
|
give the client full admin rights to your Hasura instance. See :ref:`auth` for information on
|
|
|
|
setting up authentication.
|
|
|
|
|
|
|
|
.. _docker_logs:
|
|
|
|
|
|
|
|
Hasura GraphQL engine server logs
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
You can check the logs of the Hasura GraphQL engine deployed using Docker by checking the logs of the
|
|
|
|
GraphQL engine container:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE ...
|
|
|
|
cdfbc6b94c70 hasura/graphql-engine.. ...
|
|
|
|
|
|
|
|
$ docker logs cdfbc6b94c70
|
|
|
|
|
|
|
|
{"timestamp":"2018-10-09T11:20:32.054+0000", "level":"info", "type":"http-log", "detail":{"status":200, "query_hash":"01640c6dd131826cff44308111ed40d7fbd1cbed", "http_version":"HTTP/1.1", "query_execution_time":3.0177627e-2, "request_id":null, "url":"/v1/graphql", "user":{"x-hasura-role":"admin"}, "ip":"127.0.0.1", "response_size":209329, "method":"POST", "detail":null}}
|
|
|
|
...
|
|
|
|
|
|
|
|
**See:**
|
|
|
|
|
|
|
|
- https://docs.docker.com/config/containers/logging for more details on logging in Docker.
|
|
|
|
|
|
|
|
- :ref:`hge_logs` for more details on Hasura logs.
|
|
|
|
|
|
|
|
.. _docker_update:
|
|
|
|
|
|
|
|
Updating Hasura GraphQL engine
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
This guide will help you update the Hasura GraphQL engine running with Docker. This guide assumes that you already have
|
|
|
|
Hasura GraphQL engine running with Docker.
|
|
|
|
|
|
|
|
Step 1: Check the latest release version
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The current latest version is:
|
|
|
|
|
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
<code>hasura/graphql-engine:<span class="latest-release-tag">latest</span></code>
|
|
|
|
|
|
|
|
All the versions can be found at: https://github.com/hasura/graphql-engine/releases
|
|
|
|
|
|
|
|
Step 2: Update the Docker image
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
In the ``docker run`` command or the ``docker-compose`` command that you're running, update the image tag to this
|
|
|
|
latest version.
|
|
|
|
|
|
|
|
For example, if you had:
|
|
|
|
|
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
<code>docker run hasura/graphql-engine:v1.0.0-alpha01 ...</code>
|
|
|
|
|
|
|
|
you should change it to:
|
|
|
|
|
|
|
|
.. raw:: html
|
|
|
|
|
|
|
|
<code>docker run hasura/graphql-engine:<span class="latest-release-tag">latest</span> ...</code>
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
If you are downgrading to an older version of the GraphQL engine you might need to downgrade your metadata catalogue version
|
|
|
|
as described in :ref:`downgrade_hge`
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Advanced
|
|
|
|
--------
|
2018-09-11 14:11:24 +03:00
|
|
|
|
2020-06-11 15:57:46 +03:00
|
|
|
- :ref:`Setting up migrations <migrations>`
|
2018-09-11 14:11:24 +03:00
|
|
|
|