How to run cassandra in docker
How to run cassandra in docker
1) Run `docker pull cassandra:latest`. This is to get the image used to run the cassandra node locally.2) Run `docker run -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 --name cassandra -d -ti --entrypoint=sh cassandra`. This command will create and run the docker container in the background.
Note:
- If you are looking to edit your cassandra.yaml file, restarting the docker container will not persist the change that you've made in the docker container. To solve this, you need to mount a volume that mounts the file from your local PC to the docker container. To achieve this, use this command:
-v "{absolute_path_to_your_file}:/etc/cassandra/cassandra.yaml"
For example, if I were to store my file in C:\Users\nic35, then my absolute_path_to_my_file would be:
C:\Users\nic35\cassandra.yaml.
- If you are looking to run the docker container in the background, make sure to include the flag `-d` in your command.
How to run interactive prompt in your Cassandra docker container?
`docker exec -it {docker_container_name} bash
- Make sure that the `bash` is placed at the end of the command, or else it won't work
- If you ever encounter an error that states your container is not ran, try using the following steps:
1) Run `docker pull cassandra`
2) Run `docker run --name {container_name} -d -ti --entrypoint=sh cassandra`
The above command should create and run your docker container in the background.
Let's say if your container still doesn't run, you can try the following alternative:
1) `docker commit {container_name} {new_image_name}
That would do the trick. Essentially what it is doing is, it creates an image with the same file system from the container. So you can run a brand new container with the newly created image. More info here
What if the above solution doesn't work?
If the above doesn't work, here is an alterative, and the steps you can take to resolve this:1) Ensure Cassandra, Java 8 (much preferred as many programmers find this version works) and and Python 3 (Python 2 is no longer supported) is installed locally in your PC
3) Then, edit the file. Search for `set UNINSTALL="UNINSTALL"`, and under it, add `set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202`
4) Do the same for the file nodetool.bat. Under the comment, add the same line `set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202`. The comment is in the form of `@REM {context}.
I've encountered some error, while following the above steps, what should I do?
1) Make sure that the rpc_address in the cassandra.yaml is configured to the actual IP of your PC. The cassandra.yaml file is located under cassandra installed in your PC, instead of the one in docker
Comments
Post a Comment