How can I access cassandra.yaml in Docker? - docker

I use cassandra image to create cassnadra container. I use volumes as follow:
- ./samt_tmp/cassandra_data/cassandra:/etc/cassandra/
I want create cassandra.yaml from docker in my pc but this path isn't exist.
sed: can't read /etc/cassandra/cassandra.yaml: No such file or directory
while can copy from this directory.
why can't create volume from directory?
how can create cassandra.yaml volume ?

Related

Is it possible to mount the host path or docker volume to the path in the image from dockerfile?

I want to mount my host path (or docker volume) to the path in the image from dockerfile.
Dockerfile can copy the host data or directory to the data or directory in the image.
But I want to bind or mount not copy!
It is similar to "docker run -v" option but I wonder that it is done by creating the image from dockerfile.
Is any solution for this issue?
No, as far as I am aware, a host path cannot be mounted via the Dockerfile due to the portability of docker images and the different host architectures/directory layouts etc. See dockerfile volumes note 4.
Using VOLUME within the dockerfile will create a docker volume on the host at run-time of the container, but it cannot be specified to be a host directory. This answer explains the use of dockerfile VOLUME quite well. To use a host directory, you will need to do it at run time.

How to write files to a docker container's temporary directory?

I am trying to write content(backup files) into a temporary directory inside a running Docker container.
Is there a way to create a temporary directory inside the container and write content to it?
You can bind this folder to the docker container directly using volumes.
As you do not want them changed I assume you could mount them as a read-only volume.
In that case you do not have to copy them around as you will have them accessible already in the container :)

Dockerfile vs. docker-compose VOLUME

This experiment tries to build a container using this Docker file:
FROM lambdalinux/baseimage-amzn:2016.09-000
COPY ./bundle /opt/bundle/
VOLUME /bundle
Then inside the container, create a /opt/bundle/file.txt and put some text in it. But that file did not show up in the bundle directory on the host as I expected after reading Should I include my code with COPY/ADD or a volume last paragraph:
There may be cases where you’ll want to use both. You can have the image include the code using a COPY, and use a volume in your Compose file to include the code from the host during development. The volume overrides the directory contents of the image.
Doesn't Dockerfile VOLUME do the same as docker-compose.yml VOLUME? If so, how can this be done so that changes in the host directory is reflected inside the container directory in this case?
I also created a file on the host bundle/play.txt but that did not show up inside the container /opt/bundle/...
A VOLUME instruction in the dockerfile creates a mount point but initially only maps it to Docker's internal data directory.
In order to map the volume to the host filesystem, you need to specify which path on the host should be mapped to the volume. You can do this in the docker-compose file using the volumes parameter. (Note: you can create volumes using docker-compose without declaring them in the Dockerfile.)
Note that when mapping a directory from the host to a container, the directory contents on the host will replace the contents in the container, not vice versa.

Docker volumes are partitions or subdirectories?

I declare a new volume in runtime with -v flag in docker run command. What is the created volume? Partition or only a subdirectory? Could be it maybe formatted to another filesystem(If Docker supports other fs, than AUFS)?
Using "-v" is created a link between the host folder to container. The files created in container linked folder, that documents will be stored in folder of host.
About other FS. Docker supports AUFS, btrfs, vfs, and DeviceMapper:
https://docs.docker.com/introduction/understanding-docker/

Can I populate the content of the Volume I created in Bluemix Containers?

I uploaded a Oracle11g DB image in my Bluemix Container registry.
I created a volume called oradbdata in IBM Containers using the CLI:
cf ic volume create oradbdata
Now I need to copy some content into this volume before running the container.
Is there anyway to access this volume and populate its content?
Lionel
When you start the container you can associate the volume to the desired container path; for example: volume oradbdata -> /var/lib/oradata. When the container then starts the /var/lib/oradata is mapped with your volume and, at that point, you can put data on it either at the start-up of the container or accessing the container via ssh.
I suggest adding your files into the container during the container build (e.g. into a /src directory). Then use a startup script for your app. In the script you would check if the mounted directory has the file(s) you need. If not then copy things over. Something like this:
#!/bin/bash
# Test if the volume is empty
if [ ! -f /mountpoint/testfile ]; then
# Copy the contents from the container image into the volume
cp -R /src/* /mountpoint
fi
# Now start the app here
/usr/bin/myapp

Resources