Difficulty: Intermediate
Estimated Time: 10-15 minutes

One of the easiest ways to get started with Apache Cassandra™ is using Astra DB

Need a free Astra account? You can get one at astra.datastax.com!

In this scenario, we'll learn how to:

  • Create an Astra DB keyspace
  • Create a container for cqlsh that connects to Astra DB
  • Create a table using the container
  • Insert and query data using the container

Once you know how to create a Docker container for cqlsh, you can use this knowledge to create containers for your own apps that talk to Astra DB!

Astra DB is a great Cassandra as a Service offering and Docker containers are really slick, so this is going to be fun! Let's get started!

Congratulations! You know how to create a Docker container for cqlsh and how to connect to Apache Cassandra™ via Astra DB.

Check out the official Cassandra Docker images on Docker Hub.

Was this helpful? Please give this scenario a rating (click on the stars above).

Have questions or more feedback? Send us a message.

Connect to Astra DB (Cassandra as a Service) with CQL Shell using Docker

Step 1 of 5

Create your Astra DB Database

Let's set up some environment variables to help simplify our Astra DB API access.

New to our scenarios? Click here for three easy tips.
Tip 1 - You can click lines that begin with a triangle (like the following) to see further explanation.
Try clicking on this line. This is where you would find further explanation.

Tip 2 - To paste content into the terminal, right-click in the terminal on the right-hand side of the screen and select Paste. Paste to terminal
Tip 3 - If a dark box has a bent arrow at the end, you can execute the command in that box by clicking on the box. The scenario will copy the command to the terminal and begin execution. Execute command
After you execute the command, the bent arrow changes to a check mark.

Bonus Tip! - You can click on images to enlarge them.

Thats it! You're good to go!


Step 1. Login to Astra.
Open a tab in the browser for Astra. You can login using a GitHub or Google account, or create a new Astra account.

Login to Astra

Step 2. Go to the Connection tab of your Astra DB database.
From the Astra DB dashboard, click on the database name. Then, click the Connect tab.

To connect tab

Step 3. Copy the environment variables from the Astra DB Connect tab.
From the Connect tab, click Document API from the navigation on the left. Under Step 2 of the Prerequisites, click the copy icon to copy all the export commands.

Copy the export commands

Step 4. Paste the export commands into the terminal.
Back in the Katacoda terminal, paste the contents of the clipboard at the terminal prompt. All but the last of these export commands will execute. Do NOT execute the final command yet - we need to replace <app_token> before we can execute it.

Paste export commands


Note: Do NOT execute the final export command yet!


Step 5. Find the Organization Settings.
From the Current Organization drop-down, select Organization Settings.

Find Organizational Settings

Step 6. Access Token Management.
In the left-navigation list, select Token Management.

Select Token Management

Step 7. Generate a new application token.
From the Select Role drop-down menu, select Database Administrator. Click the Generate Token button.

Generate the Token

Step 8. Copy the application token.
Click on the clipboard icon near the right edge of the token to copy the token to your clipboard. Please note that, as a security precaution, you will only be able to copy this token once. So, please take care not to overwrite the token until you have completed the next step.

Copy the token to the clipboard

Step 9. Replace <app_token> with the application token and execute the command.
Return to the Katacoda terminal. Delete <app_token> at the end of the final export command. Paste the copied token into the terminal at the end of the export command and hit <enter> to execute the command.

Paste the token from the clipboard

Step 10. Copy the client ID.
Back in the Astra DB UI, click on the clipboard icon near the right edge of the client ID to copy the ID to your clipboard. Please note that, as a security precaution, you will only be able to copy this ID once. So, please take care not to overwrite the ID until you have completed the next step.

Copy the client ID to the clipboard

Step 11. Paste the ID on the end of the command and execute it.
Return to the Katacoda terminal. Click the following to copy the first part of the export command to the terminal. Then, paste the copied ID into the terminal at the end of the export command and hit <enter> to execute the command.
export ASTRA_DB_CLIENT_ID=
Step 12. Copy the client secret.
Back in the Astra DB UI, click on the clipboard icon near the right edge of the client secret to copy the secret to your clipboard. Please note that, as a security precaution, you will only be able to copy this secret once. So, please take care not to overwrite the secret until you have completed the next step.

Copy the secret to the clipboard

Step 13. Paste the secret on the end of the command and execute it.
Return to the Katacoda terminal. Click the following to copy the first part of the export command to the terminal. Then, paste the copied secret into the terminal at the end of the export command and hit <enter> to execute the command.
export ASTRA_DB_CLIENT_SECRET=

Verify the contents of the variables we will use in this exercise with the following commands.

echo $ASTRA_DB_APPLICATION_TOKEN
echo $ASTRA_DB_CLIENT_ID
echo $ASTRA_DB_CLIENT_SECRET
echo $ASTRA_DB_ID


We can use some of these variables to help us create a keyspace named user_management, which we will use in this exercise. The following is an Astra DB DevOps command that will create the keyspace.

curl --request POST https://api.astra.datastax.com/v2/databases/$ASTRA_DB_ID/keyspaces/user_management --header "Authorization: Bearer $ASTRA_DB_APPLICATION_TOKEN"

When this command completes successfully, it produces no output.

Great! The environment is ready to go!