If you’ve followed Getting cockroachdb running on google cloud platform you’ll have a small cockroach implementation of 3 nodes running as Docker containers on a single VM on Google Cloud Platform that can run local SQL queries and which you can monitor through a browser. Note that if you haven’t reserved a static ip address (it costs something) it’ll change from time to time.

Next, you’ll want to connect to it to build an app.

You can find more on this in detail at Cockroachdb site.

Exposing ports

We already exposed port 8080 to be able to use the monitoring tool, but we also need to expose port 26257 so we can connect to the database containers. Just like before, we need to create a firewall rule for this.


And I’ll update the fw.sh script to make this repeatable.

fw.sh updated

The Docker image already contained a redirect for its ports to the VM’s 26257,
but we still have to associated this tag, cockroach-sql, with the VM.

I’ll update the script to create the instance to include this tag too

ci.sh updated

Now we are ready to go, but it’s a good idea to check if the port is actually open as expected. https://ping.eu/port-chk/ for this, which gives this result.

Creating a user

Next we need to grant access to some user and allow access to the database, in this case to the locations table. For future automation, I’ll put that in a script

us.sh

and add that to the overall script

updated whole.sh

Selecting a client

There are a number of clients to choose from, but for Node, I’ll be using pg, which you can read about here. It’s installable via npm –

Creating an app

This test app on Node will do the same query as I did locally.

and the result

For more like this, see React, redux, redis, material-UI and firebase
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.