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 want to mount onto in your docker container. For example, if you would like to mount the cassandra.yaml onto a folder called scripts in your root folder, then you can define the value of directory_of_docker_container as `/scripts/cassandra.yaml`. The `/` is the root within the docker container. It is important to note that the last part in the directory should contain the full name of the file you would like it to be called. For example, if you want to mount a CQL file that is named `data.cql`, make sure the name matches in the directory, for example, `/scripts/data.cql`, instead of `/scripts/data.cql`. Or else, docker would assume you are mounting onto a folder instead of a file.
Comments
Post a Comment