Posts

Showing posts from January, 2025

The arrangement of flags in your docker command matters!

In the official document of docker, commands are presented in the format of: docker container run [OPTIONS] IMAGE [COMMAND] [ARG...] And the arrangement stated above must be followed, or else many kind of weird errors will occur. Let's say you are trying to run a docker container interactively: docker run {image} -it --entrypoint=sh -d Guess what happens? Instead of running the image, it will instead show the following error: getopt: invalid option -- 'i' getopt: invalid option -- 't' getopt: unrecognized option '--entrypoint=sh' getopt: invalid option -- 'd' This is because in the docker documentation, it specifically says to put the [options] - the flags such as -i, -t, or -d, right before IMAGE. Therefore, if we were to switch the position, we will be able to get the result we need. For example: docker run  -it --entrypoint=sh -d  {image} This should run the docker container in the background, while enable interactivity to our container.

Mounting files from your local PC to your docker container using -v

Mounting files from your local PC to your docker container using -v There are times when you need to mount files to your docker container in order for some files to have their changes persisted. For example, in Cassandra, if you were to edit your cassandra.yaml file, the file changes will not persist if you restart your docker container. But if you don't restart, the changes would not apply. In this guide, I will show you how to mount files from your local PC to your docker container using the flag -v How to mount files from your local PC to your docker container? To do this, simply run the following command. docker run -v `{directory_of_local_pc}:{directory_of_docker_container}` {image_name} directory_of_local_pc is the absolute path of your file that you want to mount. For example, if you want to mount a file, let's call it, cassandra.yaml. So your absolute path would be `D:\docker_stuff\cassandra.yaml`. directory_of_docker_container is the absolute path of your file that you...

Running CQL scripts in Cassandra

How to run CQL scripts in Cassandra  There are 2 ways to run a CQL script, the first way would be running the following command: - cqlsh -f {directory} The second way would be using the command within the CQLSH terminal: - source '{directory}' Where does the {directory} points to? The directory points to the root of your server. For example, if you are on linux, the root would be `/`. Therefore, if you placed your scripts under the folder `scripts`, your directory would look like this `/scripts/{cql_script_name}.cql`.  I've been running the command, but it keeps saying `No such file or directory`? If you met this error, please make sure that:      - The file actually exist in the directory. You can check if by typing `ls -l {directory}`. If it doesn't exist, it will show the same error. If you are on docker, and you are unsure of how to mount your CQL file into your container, you can check out this guide.      - The CQL file has the correct exten...

NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED 127.0.0.1:9042

NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED 127.0.0.1:9042 Why `All host(s) tried for query failed`? All host(s) tried for query failed occured, because the app could you find any Cassandra node to connect to. What is the fix? In order to fix this, we need to configure the cassandra.yaml file. You can find the file in /etc/cassandra/cassandra.yaml. Once you've located your cassandra.yaml, we need to find the `rpc_address` located in the cassandra.yaml file. What `rpc_address` do is, it defines from which client should the Cassandra node listens to. So if you are creating a Node JS server with an IP address of, let's say, 192.168.1.1, the `rpc_address` should match that. By default, the `rpc_address` is set to 0.0.0.0. In order to fix it, find out what IP address your server is using, and set it to the `rpc_address`.  Note that localhost, nor the default IP would work if you run your Cassandra node in Do...

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 t...