Home > Mobile >  Why does Cassandra docker image require root privileges to run?
Why does Cassandra docker image require root privileges to run?

Time:05-10

I am using the latest Cassandra docker image. When I run it with root privileges, cqlsh is able to connect to Cassandra service as expected:

$ sudo docker run --name mycassandra -d cassandra:latest
$ sudo docker exec -it mycassandra bash
# cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.3 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> 

However, if I run docker image with normal user privileges, I get an error when using cqlsh:

$ docker run --name mycassandra1 -d cassandra:latest
$ docker exec -it mycassandra1 bash
# cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1:9042': 
ConnectionRefusedError(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: 
Connection refused")})

I prefer not to run docker image as sudo. Wondering why Cassandra image requires sudo privileges. Thanks.

CodePudding user response:

It looks like you're a member of the docker group since you can run docker without sudo. Whether you run it with or without sudo shouldn't make a difference. The container runs as root in both cases, which you can verify by the # bash prompt in both cases.

What I think is happening is that you're trying to run cqlsh before the container has finished starting up. Check the container log and make sure you see Startup complete before you try running cqlsh.

  • Related