DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Optimizing Pgbench for CockroachDB Part 2
  • Optimizing Pgbench for CockroachDB Part 1
  • Using CockroachDB Workloads With Kerberos
  • The Evolution of Scalable and Resilient Container Infrastructure

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Running CockroachDB With Docker Compose - Part 1

Running CockroachDB With Docker Compose - Part 1

This is the first post in a series of tutorials to demonstrate how to easily integrate CockroachDB into your daily work. Today, we're covering docker-compose and a single node Cockroach cluster.

By 
Artem Ervits user avatar
Artem Ervits
DZone Core CORE ·
Dec. 31, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

Over the next few weeks, I will be publishing a series of tutorials on CockroachDB and various third-party tools to demonstrate how easy it is to integrate CockroachDB into your daily work. Today, we're covering docker-compose and a single node Cockroach cluster as that will be a foundation for the next blog post.

CockroachDB and Docker Compose

This is the first in a series of tutorials on CockroachDB and Docker Compose.

  • Information on CockroachDB can be found here.
  • Information on Docker Compose can be found here
  1. Install Docker Desktop

Because we already have an official CockroachDB docker image, we will use that in our docker-compose.yml file. We recommend you use one of the current tags instead of latest.

  1. create a docker-compose.yml file and enter the following:
version: '3.9'

services:

 crdb:
   image: cockroachdb/cockroach:v21.2.3
   ports:
     - "26257:26257"
     - "8080:8080"
   command: start-single-node --insecure
   volumes:
     - "${PWD}/cockroach-data/crdb:/cockroach/cockroach-data"


  1. Start the docker-compose with:
docker-compose up


It will run crdb in the foreground. To run crdb in the background, pass -d flag to docker-compose:

docker-compose up -d


To view the current logs when run in the background:

docker-compose logs
ttaching to crdb-compose_crdb_1
crdb_1  | *
crdb_1  | * WARNING: RUNNING IN INSECURE MODE!
crdb_1  | *
crdb_1  | * - Your cluster is open for any client that can access <all your IP addresses>.
crdb_1  | * - Any user, even root, can log in without providing a password.
crdb_1  | * - Any user, connecting as root, can read or write any data in your cluster.
crdb_1  | * - There is no network encryption nor authentication, and thus no confidentiality.
crdb_1  | *
crdb_1  | * Check out how to secure your cluster: https://www.cockroachlabs.com/docs/v19.2/secure-a-cluster.html
crdb_1  | *
crdb_1  | *
crdb_1  | * WARNING: neither --listen-addr nor --advertise-addr was specified.
crdb_1  | * The server will advertise "f93eaa8e1319" to other nodes, is this routable?
crdb_1  | *
crdb_1  | * Consider using:
crdb_1  | * - for local-only servers:  --listen-addr=localhost
crdb_1  | * - for multi-node clusters: --advertise-addr=<host/IP addr>
crdb_1  | *
crdb_1  | *
crdb_1  | *
crdb_1  | * INFO: Replication was disabled for this cluster.
crdb_1  | * When/if adding nodes in the future, update zone configurations to increase the replication factor.
crdb_1  | *
crdb_1  | CockroachDB node starting at 2019-12-20 17:11:29.7723213 +0000 UTC (took 0.7s)
crdb_1  | build:               CCL v19.2.2 @ 2019/12/11 01:33:43 (go1.12.12)
crdb_1  | webui:               http://f93eaa8e1319:8080
crdb_1  | sql:                 postgresql://root@f93eaa8e1319:26257?sslmode=disable
crdb_1  | RPC client flags:    /cockroach/cockroach <client cmd> --host=f93eaa8e1319:26257 --insecure
crdb_1  | logs:                /cockroach/cockroach-data/logs
crdb_1  | temp dir:            /cockroach/cockroach-data/cockroach-temp692438876
crdb_1  | external I/O path:   /cockroach/cockroach-data/extern
crdb_1  | store[0]:            path=/cockroach/cockroach-data
crdb_1  | status:              initialized new cluster
crdb_1  | clusterID:           db57d0eb-3df5-4c58-bd2f-6c426a038ed7
crdb_1  | nodeID:              1


  1. Connect to crdb shell to interact with the database

Find the ID of the container with:

docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                              NAMES
f93eaa8e1319        cockroachdb/cockroach:v19.2.2   "/cockroach/cockroac…"   52 seconds ago      Up 51 seconds       0.0.0.0:8080->8080/tcp, 0.0.0.0:26257->26257/tcp   crdb-compose_crdb_1


Copy the ID of the container and pass it to the docker exec command.

docker exec -ti f93eaa8e1319 ./cockroach sql --insecure
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v19.2.2 (x86_64-unknown-linux-gnu, built 2019/12/11 01:33:43, go1.12.12) (same version as client)
# Cluster ID: db57d0eb-3df5-4c58-bd2f-6c426a038ed7
#
# Enter \? for a brief introduction.
#
root@:26257/defaultdb>


  1. Shut down your environment:
docker-compose down


Now, let's talk about what the docker-compose file is actually doing. The main focus of this tutorial is on the crdb service and general intricacies of docker-compose are beyond the scope of this tutorial.

 crdb:
   image: cockroachdb/cockroach:v21.2.3


This line says this service is called crdb, you can name it any way you'd like and we're pulling the latest stable image from docker hub which is 21.2.3 at the time of writing.

   ports:
     - "26257:26257"
     - "8080:8080"


This line says map the container ports for crdb for the CLI, 26257 and admin-ui, 8080 on the host. When this docker-compose script is executing, you should be able to navigate to the admin-ui with http://localhost:8080 url. You used port 26257 when you connected with the ./cockroach sql --insecure command.

The following line says to start a single node instance of crdb. CRDB is a multi-node database and start-single-node is a stop-gap for those times when you need to run a quick single-node instance. Read more here.

   command: start-single-node --insecure


Finally, the last line maps the host's current directory to your docker's mount point where crdb logs and data will reside. You should be able to browse those artifacts even after the container terminates.

   volumes:
     - "${PWD}/cockroach-data/crdb:/cockroach/cockroach-data"


Hope you enjoyed this tutorial and will come back for part 2 when I publish it shortly.

Docker (software) CockroachDB

Published at DZone with permission of Artem Ervits. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Optimizing Pgbench for CockroachDB Part 2
  • Optimizing Pgbench for CockroachDB Part 1
  • Using CockroachDB Workloads With Kerberos
  • The Evolution of Scalable and Resilient Container Infrastructure

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!