Mount Local file on windows to a Docker container

Imagine you have a web application container that needs to access configuration settings stored in a file on your host system. This file might contain sensitive information like database credentials or API keys. Storing such sensitive data directly within the container image can lead to security risks, particularly when sharing the image. To mitigate this issue, Docker provides storage options that help bridge the gap between container isolation and your host machine’s data.

Docker offers two primary storage options for persisting data and sharing files between the host machine and containers: volumes and bind mounts.

Here we will use the bind mount

docker run -it --mount type=bind,source=d:\\MyFolder\\temp,target=/app/data wordcounterapp:latest -s /app/data/config

e.g The above is the example of a console app running in a container . It counts the words in a sentence . I ve put a sentence in a file on my d drive in windows and mounted it to container and passed the argument 

I have a windows 11 host machine so my example is the use case where i have file in my local machine in a directory called "temp" and i want to mount it to a container .so i will mount the content of the directory on my source system to the container file system.
so in the above command , the source is d:\\MyFolder\\temp
target is /app/data/config

Note: Please make sure that file path is correct and there is no spaces for source and target values. for e.g
the space shown below between cmdline argument and value will also give error

Leave a Reply