The tool I'm using is delivered in a Docker image. Since installing the tool is extremely complicated with a bunch of dependencies, I want to work on the host with my IDE, but run it on the container.
So after download and load the image, I run:
sudo docker run -it -v /home/myself/WIP/thetool:/home/thetool name/label
Without mounting, the tool is located under /home/thetool
, but with mounting, this folder is empty (since the folder in the host is empty).
Do I need to copy the tool from the container, then mount it, or there is a way to do it directly.
How to Mount Local Directories using docker run -v. Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to your container. For example, you can start a MySQL database and mount the data directory to store the actual data in your mounted directory.
The Docker CLI provides the –mount and –volume options with a run command to bind a single file or directory. Both flags work similarly but have different syntaxes. As a result, we can use them interchangeably.
A Bind Mount is a storage area (file/directory) on your local machine available inside your container. So any changes you make to this storage space (file/directory) from the outside container will be reflected inside the docker container and vice-versa.
You can actually make that work with a docker volume with explicit device mount point.
If the directory /home/myself/WIP/thetool is empty, do the following:
Create a docker volume as such:
docker volume create --driver local \
--opt type=none \
--opt device=/home/myself/WIP/thetool \
--opt o=bind \
tool_vol
Start the container and mount the created volume:
sudo docker run -it -v tool_vol:/home/thetool name/label
Now the data that is in /home/thetool
inside the container will be available inside /home/myself/WIP/thetool
even though the host folder was initially empty.
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