cannot connect to cassandra docker with cqlsh
Try to change your docker run command as :
docker pull cassandradocker run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160 -d cassandra
This will ensure the docker container maps to the IPv4.
9160 - Thrift client API9042 - CQL native transport port
From your PHP application, you have to connect to the Thrift port. Please follow the example as in http://support.qualityunit.com/942764-Example-of-PHP-application-readingwriting-to-CassandraIn the above example, for connecting to the cassandra container from the same machine where the container is running, you can still use the same TSocket('127.0.0.1', 9160)
.
If you plan to connect from a different machine, then you have to use TSocket('IP/Domain name', 9160)
in this, the IP/ Domain name is the identifier for the machine where the docker container is running.
If your PHP application is in another docker container on the same machine, first you have to link the containers, then you can use the TSocket('alias name', 9160)
in this, the alias name is the name you have for the link.
try { // Make a connection to the Thrift interface to Cassandra $socket = new TSocket('127.0.0.1', 9160);