How to Run a Cassandra Operation in Docker
Containers thrive in a world of modern applications that demand faster delivery, better portability and seamless scalability. Gartner predicts that by 2022, more than 75% of global organizations will be running containerized applications in production.
The steam behind this growing trend is none other than Docker. Docker is an open source containerization platform that lets developers package applications into containers that include everything they need to run in different environments. For enterprises, however, it can be tricky to manage individual Docker containers at scale, giving way to the popular container orchestration platform: Kubernetes (K8s).
In short, Kubernetes makes it easy to deploy, manage and scale containers — and is the dominant orchestration platform used in enterprises today. This makes learning Kubernetes a must for every budding application developer; but first, you need to understand containers and Docker.
In this Cassandra Operations in Docker workshop, you’ll become familiar with Docker and learn how to deploy a cloud native application in containers. You’ll also dabble in a few other technologies that make app development easier:
- Spring Boot to pull the backend app image from Docker.
- Angular web application to run the frontend app in Docker.
- Apache Cassandra as your distributed, NoSQL database.
To wrap it all up, we’ll give you a hands-on exercise where you’ll go through each step of deploying a Cassandra-based app in Docker, all within an interactive training environment.
Let’s start from the top. A container is a lightweight software package that bundles everything needed to run an application: code, runtime, system tools, system libraries and settings. This makes it easy for developers to run an app quickly and reliably in different production environments.
But wait a minute, how are containers different from virtual machines (VMs)?
While containers virtualize the operating system, VMs emulate hardware like CPU, disk and networking devices to get around limited infrastructure. Simply put, containers are lighter, more efficient and more portable than VMs.
Now that’s clear, we can dive into Docker.
To recap, the Docker platform lets you package your app within an all-in-one container, allowing you to:
- Develop, ship and run software faster and more consistently.
- Easily scale up or down to dynamically manage workloads.
- Run more workloads on the same hardware.
- Deploy apps locally, on-premises, in the cloud or in a combination of environments.
Docker uses a client-server architecture, where the Docker client talks to the Docker daemon. The daemon listens for API requests, manages Docker objects (such as images, containers, networks, plugins), and takes care of building and running your containers.
Here’s how it all comes together.
To get you up to speed with the different parts, we’ll briefly cover a few concepts as well as the Docker objects and clients you’ll be using in this workshop.
A Docker image is a read-only file that combines the application and the environment needed to run it (libraries, tools, files, etc.), and acts as a set of instructions to build a Docker container.
It’s like a template that’s often based on another image with some customization. For example, you could build an image from a Node.js image, and it’ll bring along everything needed to run your application.
These images are typically stored in a Docker registry, which can be private for your own use, or you can use the public Docker Hub where you can find and reuse images stored by others.
Dockerfiles define the steps to build an image. It lays out the commands needed to build the application and can even download, install and run the software for it to run.
To create your own image, you can use the build command from the Docker command line interface (CLI). You can make changes to a specific image layer in the Dockerfile and only that layer will update when you rebuild the image. This is one of the reasons images are so lightweight and efficient.
In short, images run in containers and containers communicate through Docker networks.
What makes Docker networks so powerful is you can connect applications running in Docker containers with other applications, even if they’re not deployed on Docker or are on different operating systems. It does this by creating a platform-agnostic network for containers so they can communicate with each other, and you can manage them whether they’re on Linux, Windows, iOS or a mix of them.
Docker Compose is a client that lets you manage multicontainer applications. You can use a docker-compose.yaml file to configure all your app’s services with simple commands. You can use this tool in production, staging, development and testing environments.
So that’s the theoretical part done, but now comes the good bit: using it yourself.
Scenario: Deploy a Sample App on Docker
Ready to give it a try? We set up an interactive Katacoda scenario so you can safely put theory into practice while learning how to run a Cassandra-based application in Docker.
In this scenario, you’ll deploy an Angular frontend app, a Spring Boot backend app and a Cassandra cluster in Docker containers. It’ll only take you 15 minutes, and you’ll learn how to:
- Create a Docker network.
- Pull images from Docker Hub and run them in containers.
- Deploy a Cassandra cluster.
- Deploy a Spring Boot microservice.
- Test the microservice-to-database connection.
- Deploy the Angular web application.
- Test the web application.
- Shut down the containers.
- Re-create the application using Docker Compose.
It might sound like a lot, but don’t worry, we’ll guide you step by step. So roll up your sleeves, flex your fingers, and scroll to the bottom of the Running a Cassandra Application in Docker page and click “Start Scenario.”
Once you’ve completed it, you can jump into the world of Kubernetes to learn all about managing containers at scale — a must-know in any enterprise. A good starting point is our first workshop on deploying a sample application with Cassandra in Kubernetes. Keep the momentum going!
This article is part of a learning series DataStax created to show you how to successfully run Apache Cassandra in Kubernetes. Each workshop helps you level up a new skill and introduces you to all the concepts you need to pass the K8ssandra Certification Exam.