Multiple Instances of Hasura

v2.0.9 & v1.3.1

Recently I was in a fix.

I had to run two instances of Hasura on my local machine that was being used for two different projects; I was already running one instance.

One of the projects is using an older version of Hasura (v1.3.1) and the other using a newer version (v2.0.9). Now both of these versions have a lot of things not in common, so its quite a challenge as it is, to use both parallely, or at least getting adapted to it.

So, if you are using Hasura for the first time, its pretty easy to set up. There are a bunch of articles telling you how to do that. Just use this one to help yourself.

But if you look closely while setting it up, there are minute nuances, too easy to overlook.

For example:

  • The default console port is 9695,
  • The default migrate api port is 9693,
  • And, the default graphql port is 8080.

Now now, you dont have to worry about any of these if you are going to use hasura as a hobby level project or just use it for one particular project.

Enter using multiple instances.

When you have to use Hasura for another project, you cannot go about setting up hasura again the default way. There are caveats to it, this time.

So, I am gonna leave what I have done to get it up and running with one Hasura instance already in the mix.

1.

ports:
      - "8090:8090"

[HOSTPORT:CONTAINERPORT] - The default is 8080:8080, here you can any other combination except this if you are already using it in the running instance. Be sure to know what ports are free in the host machine. This trick goes into the docker-compose.yml.

2.

endpoint: http://localhost:8090/

Inside the config.yml, make sure this you do this small edit. This essentially needs to shadow the port you have used in HOSTPORT in the above point.

3.

HASURA_GRAPHQL_SERVER_PORT= 8090

Add this beauty to your .env. If you scroll up a bit, you will quickly see that the default graphql port is 8080.
This is the port on which graphql-engine should be served

4.

hasura console --console-port [PORT] --api-port [PORT]

This is how you run the console command. When we provide the option --console-port xxxx, it tells hasura to use a port other than the default for serving console. Similarly, the --api-port xxxx tells hasura to use another port for serving migrate api.
And btw, please fill them xs with some numbers corresponding to free ports.


With all of these said and done, you should have another Hasura instance running on your machine. It took me some time to get this up and running.. so if you are from the community that use Hasura day in day out for work, please help by sharing this article in however way you feel like.


Sources :