Conceptual Struggle: how does a docker container interact with a Virtual Machine?


First I am running a virtual machine linux box that has docker installed, and when I need to use Linux, I push linux containers locally and pull them onto the linux VM.

Here is my question: “How does a docker container gain access to the virtual machine directories/folders?”

If I am ssh’d into my virtual machine, I have my own hierarchy of folders.
If I run my docker container interactively, this container has its own hierarchy of folders.

The problem: What if I have a script in my container, that needs to process a file on my virtual machine?

I know that you can mount a volume of a local directory, and build the container, then the container has access to the local directory as a volume.

Can you mount a volume AFTER you built a docker container? can I build the docker container, and afterward add the volume?

thank you very much

this I found helpful