Skip to main content
Version: v2.x

Auto-apply Migrations and Metadata


Hasura ships a special cli-migrations Docker image which can be used to automatically apply Migrations and Metadata when the server starts:


You can find the image on DockerHub for various platforms here.

This container image also includes the Hasura CLI at /bin/hasura-cli and can be used for running any other CI/CD scripts in your workflow too.

Applying migrations

The migrations and metadata directories created by the Hasura CLI in a Hasura project can be mounted at the /hasura-migrations and /hasura-metadata paths of this Docker container and the container's entrypoint script will automatically apply the migrations and metadata before starting the server. If no directory is mounted at the designated paths, the server will start and ignore the Migrations and/or Metadata.

You can also mount the migrations/metadata directories at some location other than the above by setting the following environment variables:


Once the Migrations and Metadata are applied, the container resumes operation as a normal Hasura GraphQL engine server.


# Start Hasura after applying the Migrations and Metadata present in the Hasura project
docker run -p 8080:8080 \
-v /home/me/my-project/migrations:/hasura-migrations \
-v /home/me/my-project/metadata:/hasura-metadata \
-e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:@postgres:5432/postgres \

Applying only metadata

If you're managing migrations with a different tool and want to use this image to apply only the metadata, mount the metadata directory of your Hasura project at the /hasura-metadata path of this Docker container the container’s entry point script will apply the metadata before starting the server.