CockroachDB in Single User Mode on Docker

I’ve been using CockroachDB for a while now, but when I first tried to use it locally I followed the instructions here, however, they are a bit over the top for my needs. I don’t want three nodes, I don’t want three volumes, I don’t want a network. All I want to do is run a single node to try out some things.

The documentation talks about using the cockroach start-single-node command, but it doesn’t mention how to do this in Docker. It took a bit of trial and error to get it working.

Here is how to do it.

Step 1

Download the image, and start the container. This will create a container named mycockroach and start it in the background. It will expose ports 26257 and 8080 to the host machine. The --insecure flag is required to allow connections without SSL. Port 26257 is the default port for the SQL interface, you would use this from a Postgres client (I won’t be connecting to this port in this example). 8080 is the default port for the web administration interface.

docker run -d --name=mycockroach -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:latest start-single-node --insecure

Step 2

Connect to the running docker container, and open start the Cockroach SQL prompt.

docker exec -it mycockroach ./cockroach sql --insecure

Now you can use Postgres commands to create a databases, perform queries, etc.

Step 3

Stop the container.

docker stop mycockroach

Step 4 (optional)

Restart the container.

docker start mycockroach

That’s it. You now have a single node CockroachDB running in Docker, easy when you know how!

comments powered by Disqus

Related