Is it possible to pass a local file for CQL commands to a Cassandra Docker container?
Using docker exec
fails as it cannot find the local file:
me@meanwhileinhell:~$ ls -al
-rw-r--r-- 1 me me 1672 Sep 28 11:02 createTables.cql
me@meanwhileinhell:~$ docker exec -i cassandra_1 cqlsh -f createTables.cql
Can't open 'createTables.cql': [Errno 2] No such file or directory: ‘createTables.cql'
I would really like not to have to open a bash session and run a script that way.
The container needs to be able to access the script first before you can execute it (i.e. the script file needs to be inside the container). If this is just a quick one-off run of the script, the easiest thing to do is probably to just use the docker cp
command to copy the script from your host to the container:
$ docker cp createTables.cql container_name:/path/in/container
You should then be able to use docker exec
to run the script at whatever path you copied it to inside the container. If this is something that's a work in progress and you might be changing and re-running the script while you're working on it, you might be better off mounting a directory with your scripts from your host inside the container. For that you'll probably want the -v
option of docker run
.
Hope that helps!
If you want docker container sees files in host system, the only way is to map volume. You can mapped current directory to /tmp and run command again docker exec -i cassandra_1 cqlsh -f /tmp/createTables.cql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With