I am trying to edit cassandra.yaml which is inside docker container at /etc/cassandra/cassandra.yaml, I can edit it from logging inside the container, but how can i do it from host?
Multiple ways to achieve this from host to container. You can simple use COPY or RUN in Dockerfile or with basic linux commands as sed, cat, etc. to place your configuration into the container. Another way you can pass environment variables while running your cassandra image which will pass those environment variables to the spawning container. Also, can use the docker volume mount it from host to container and you can map the configuration you want into the cassandra.yaml as shown below,
$ docker container run -v ~/home/MyWorkspace/cassandra.yaml:/etc/cassandra/cassandra.yaml your_cassandra_image_name
If you are using Docker Swarm then you can use Docker configs to externally store the configuration files(Even other external services can be used as etcd or consul). Hope this helps.
To edit cassandra.yaml :
1) Copy your file from your Docker container to your system
From command line :
docker ps
(To get your container id)
Then :
docker cp your_container_id:\etc\cassandra\cassandra.yaml C:\Users\your_destination
Once the file copied you should be able to see it in your_destination
folder
2) Open it and make the changes you want
3) Copy your file back into your Docker container
docker cp C:\Users\your_destination\cassandra.yaml your_container_id:\etc\cassandra
4) Restart your container for the changes to be effective
Install vim
on your docker container and edit the file on the container directly (Assumption: You are comfortable using vim).
- Enter bash mode on your container
$ docker exec -it <container_id/container_name> bash
- Update package manager and install vim
:/# apt update
:/# apt install vim
- Edit your file with vim.
:/# vim /etc/cassandra/cassandra.yaml
- Get out of container's interactive mode (back to your OS's terminal.
:/# exit
- Restart your container for changes to cassandra.yaml to take effect
$ docker restart <container_id/container_name>
© 2022 - 2025 — McMap. All rights reserved.