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?
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.
Port is still not exposed outside Try this
Do docker ps you should see something like this
For more info : https://docs.docker.com/engine/reference/commandline/run/
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With