Reputation: 539
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?
Upvotes: 15
Views: 22272
Reputation: 60134
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"
Upvotes: 9
Reputation: 6603
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/
Upvotes: 31