Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to cassandra running in Docker

I'm trying to run Cassandra in a docker container and connect to it from my Mac (the host) but I keep getting Connection refused errors.

The docker command:

=> docker run --rm --name cassandra -d cassandra:3.11 -p 9042:9042

=> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                    NAMES
4ecc9dcd8647        cassandra:3.11      "/docker-entrypoin..."   33 minutes ago      Up 33 minutes       7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp   cassandra

=> cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': 
error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: 
Connection refused")})

If I'm executing bash shell in the instance:

=> docker exec -it cassandra bash

I can run the cqlsh and connect to cassandra locally.

What am I missing?

like image 389
ayun12 Avatar asked Dec 06 '17 10:12

ayun12


People also ask

Can Cassandra be containerized?

Designed to handle large volumes of data across commodity servers, Cassandra benefits from being containerized. In fact, it is one of the most popular images in the DockerHub with over 5 million pulls. This guide will present best practices for running Cassandra in Docker containers.


2 Answers

Port is still not exposed outside Try this

  • docker run -p 9042:9042 --rm --name cassandra -d cassandra:3.11

Do docker ps you should see something like this

  • 0.0.0.0:9042->9042/tcp

For more info : https://docs.docker.com/engine/reference/commandline/run/

like image 180
sanath meti Avatar answered Sep 19 '22 14:09

sanath meti


Anything passed after docker image name it considers argument to the container entrypoint.

cassandra:3.11 -p 9042:9042

so actually docker pass -p 9042:9042 this as an argument to the entrypoint, you can very this by inspecting docker container.

To run and publish port

docker run -it  - - name cassandra -e CASSANDRA_PASSWORD=cassandra --rm docker.io/bitnami/cassandra:3-debian-10

Once container up then verify connection

docker exec -it cassandra bash -c "cqlsh -u cassandra -p cassandra"
like image 22
Adiii Avatar answered Sep 21 '22 14:09

Adiii