Start HBase Using Docker

In this article, we will simply see how to start HBase service using Docker. For those of you who do not know, HBase is a non-relational database by Apache Software Foundation. Mainly used for storing and managing very large Datasets. In this article, we will run an HBase Docker image and then also start HBase Shell mode to execute some HBase queries examples in shell. P.S. This does not include the HBase Docker Compose file of any sort. 

Prerequisites

Table of Content

  • What is HBase Database? 
  • Run HBase Docker Image 
  • Start HBase Shell  
  • HBase Queries Examples
  • FAQ 

What is HBase Database?

HBase is a non-relational database management system built on top of Apache Hadoop. It is fault-tolerant. It provides real-time data access from and to HDFS. HBase also performs compressions of data. It can hold billions of records of data and provides low latency in fetching records from those big data. 

STEP 1: Run HBase Docker Image

First thing first, you need to download the HBase Docker image. This image is compiled with multiple services such as Apache HBase, Thrift server, Zookeeper, etc. This will be the only Docker image that you would need to run in order to start the HBase service. Open up a terminal and execute the following command to start the HBase Docker image: 

				
					docker run --name=hbase-docker -h hbase-docker -d -v //data://data dajobe/hbase 
				
			

The above command will first pull the Docker image from the Docker hub and then run the service on your localhost machine. The following image shows the list of Docker containers running. 

Running HBase Docker Image
Running HBase Docker Image

STEP 2: Start HBase Shell

Earlier we started the HBase Docker Container. Now we need to start the HBase Shell interactive terminal. In order to do that, we need to Go inside the Docker container that we just started. We need to copy the container ID of the HBase container. Execute the following command: 

				
					docker ps 
				
			

This will show you a bunch of information about the running container and you can copy the container ID from this. Afterward, execute the following command to go inside the Docker HBase container. 

				
					docker exec -it <Container ID> bash 
				
			

Once inside, execute the following command to start the interactive shell mode for HBase: 

				
					hbase shell 
				
			

The following image shows you all the above steps accordingly. 

Running HBase Shell with Docker Image
Running HBase Shell with Docker Image

STEP 3: HBase Queries Examples

Now that we have entered into HBase shell mode, we can execute HBase queries. So, let’s take a look at a few basic HBase Queries Examples: 

Create Table:

This will create a table named ‘transaction’ and the remaining fields would be the columns.
create ‘transaction’, ‘amount’, ‘card_type’, ‘websitename’, ‘countryname’, ‘datetime’, ‘transactionID’, ‘cityname’, ‘productname’

Show tables list:

list

Insert into Table:

put ‘transaction’, ‘2’, ‘card_type’, ‘MasterCard’
put ‘transaction’, ‘3’, ‘card_type’, ‘Visa’
put ‘transaction’, ‘4’, ‘card_type’, ‘MasterCard’
put ‘transaction’, ‘5’, ‘card_type’, ‘Maestro’
put ‘transaction’, ‘1’, ‘amount’, ‘50.87’
put ‘transaction’, ‘2’, ‘amount’, ‘1023.2’
put ‘transaction’, ‘3’, ‘amount’, ‘3321.1’
put ‘transaction’, ‘4’, ‘amount’, ‘234.11’
put ‘transaction’, ‘5’, ‘amount’, ‘321.11’

Count Total Rows in Table:

count ‘transaction’

Fetch Item from Table:

get ‘transaction’, ‘2’
get ‘transaction’, ‘5’

Fetch All from Table:

scan ‘transaction’

Delete a Cell Value:

delete ‘transaction’, ‘4’, ‘card_type’

Delete a Row in Table:

deleteall ‘transaction’, ‘4’

Drop Entire Table:

disable ‘transaction’
drop ‘transaction’

FAQ

1. Why Use HBase?
As mentioned here:
“HBase provides a dual approach to data access. While it’s row key based table scans provide consistent and real-time reads/writes, it also leverages Hadoop MapReduce for batch jobs. This makes it great for both real-time querying and batch analytics. Hbase also automatically manages sharding and failover support.”

2. Is HBase NoSQL Database?
Yes. HBase is an open-source NoSQL database that follows a columnar format for storing large data.

3. What’s Docker Used For?
Docker is used for running isolated applications or services in a compact container, with a very minimalistic list of dependencies, to be deployed on a server machine.

4. How Dockers Work?
As mentioned in their official documentation:
“Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, which lets you work with applications consisting of a set of containers.”

5. Who Own Docker?
Mirantis, a cloud computing company acquired Docker in 2019.

And that’s a wrap! 

I hope this tutorial helped you learn how to start HBase service using Docker. Feel free to leave a review in the comment section below.

Have a great one!