Starting CockroachDB in Single User Mode with a Dockerfile

A few months ago, I wrote a post showing how to start CockroachDB in single user mode on Docker using the docker run command. This post shows how to do the same thing using a Dockerfile.

The Dockerfile

The docker file is very simple.

It pulls the latest image for CockroachDB. Sets the user and password environment variables, so you can connect the database using a traditional database client. Then it invokes the start-single-node command with the --insecure flag.

FROM cockroachdb/cockroach:latest
CMD ["start-single-node", "--insecure"]
Build the image

Run the following command to build the image -

docker build -t cockroachdockerfile .

Start the container

The below command starts the container and exposes ports 26257 and 8080 to the host machine.

docker run -d --name=mycockroachdockerfile -p 26257:26257 -p 8080:8080 cockroachdockerfile
Connect to the SQL interface

Now all that is left is to connect to the SQL interface. Here I open the running container and use the cockroach executable to connect to the database. But you can use a database client like Toad or Datagrip on port 26257 too.

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

That’s it. You now have a single node CockroachDB running in Docker using a Dockerfile.

comments powered by Disqus