Can someone tell me how to change cassandra.yaml inside a docker container? I want to enable password authentication inside docker for cassandra access.
2 Answers
If you're using the official Cassandra Docker image, you'll already have the docker-entrypoint.sh. See: https://github.com/docker-library/cassandra/blob/master/docker-entrypoint.sh for some of the variables already defined, as examples.
To have these included when your container starts, you could:
- fork and edit the docker-entrypoint.sh starting at (currently) line 51 to add your own variables like this:
for yaml in \
broadcast_address \
broadcast_rpc_address \
[your_selected_yaml_variable] \
...
- include the values you want to override in docker-compose.yml like this:
environment:
- CASSANDRA_SEEDS=DC1C1,DC1C2,DC2C1,DC2C2
- CASSANDRA_CLUSTER_NAME=Dev_Cluster
- CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch
- CASSANDRA_[YOUR_SELECTED_YAML_VARIABLE]

- 1,516
- 1
- 11
- 21
You could create a docker entry point (basically it'a script file that you instruct Docker to copy on the container and it's defined as entrypoint).
COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["bin/sh", "/docker-entrypoint.sh"]
In that file you can do whatever changes you like on cassandra.yaml file using sed.
sed -ri '/^# data_file_directories:/{n;s/^#.*/'" - $CASSANDRA_DATA_DIRECTORY"'/}' "$CASSANDRA_CONFIG/cassandra.yaml"
Note that $CASSANDRA_DATA_DIRECTORY and $CASSANDRA_CONFIG are some variables defined in advance.

- 2,942
- 7
- 14