How to actually bind mount a file in Docker for Windows
NickName:swasheck Ask DateTime:2018-01-09T07:19:28

How to actually bind mount a file in Docker for Windows

I'm attempting to update the sebp/elk Logstash configuration following the documentation here. I'm running into a situation in which the host file that I am attempting to mount is being mounted as a directory in the container.

I found this related question How to mount a single file in a volume but the notion of running with PWD didn't work for me on Windows as I got the following error: C:\Program Files\Docker\Docker\Resources\bin\docker.exe: invalid reference format

I'm running Docker on Windows 10 (Build 16299.192)

λ docker version
Client:
 Version:      17.09.1-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:22:26 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.09.1-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:28:28 2017
 OS/Arch:      linux/amd64
 Experimental: true

My Docker run command is:

docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it -v d:/docker/elk/logstash-snmp.conf:/etc/logstash/conf.d/logstash-snmp.conf --rm --name elk sebp/elk

I've been able to run other containers with persistent storage out of this disk (SQL Server, Redis, Exist-DB), but I'm not sure if I'm missing something on this. How can I tell Docker to actually mount this as a file and not as a directory.

Copyright Notice:Content Author:「swasheck」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48159422/how-to-actually-bind-mount-a-file-in-docker-for-windows

Answers
Bryan Jyh Herng Chong 2018-04-28T13:33:22

This works for me:\n\nNote: This approach addresses W10 Home Edition with Docker Toolbox and VirtualBox.\n\nOverview: Create a folder in local-machine, mount this as a shared folder in Docker VM, use this shared folder as a bindmount to Docker container. \n\n\nStop docker VM using docker-machine stop default\nOpen VirtualBox, find default go to Settings > Shared Folder\nYou will see c/Users is binded to your c:\\Users\nAdd a new shared folder, note the name it is assigned. Let's name this as [local-shared]\nExit Settings\ndocker-machine start default\nOnce started, docker-machine ssh default\nsudo vi /mnt/sda1/var/lib/boot2docker/profile\nAppend the following:\n\n # create a directory in VM\n mkdir /home/docker/[foldername]\n # mount/map shared folder on localmachine to directory\n sudo moun -t vboxsf -o uid=1000,gid=50 [local-shared] /home/docker/[foldername] \n\nSave and exit ssh.\ndocker-machine stop default\ndocker-machine start default (or perhaps docker-machine restart default)\nnow docker container run -d -p 1234:6789 -v /[local-shared]/sub-dir:/[container-dir] dockerImage2Run\n\n\nAnd it should work.\n\nRef: http://support.divio.com/local-development/docker/how-to-use-a-directory-outside-cusers-with-docker-toolbox-on-windowsdocker-for-windows",


More about “How to actually bind mount a file in Docker for Windows” related questions

How to actually bind mount a file in Docker for Windows

I'm attempting to update the sebp/elk Logstash configuration following the documentation here. I'm running into a situation in which the host file that I am attempting to mount is being mounted as a

Show Detail

How can Docker Desktop mount Windows Volumes?

Let's say you're on Windows and you want to mount a volume like so: docker run --name nginx -v "C:\\my\\path:/usr/share/nginx/html" -p "8080:80" nginx This works perfectly with

Show Detail

How to mount a NFS file share inside a Windows Docker Container

I am running Docker on a Windows Server 2022. I need to start a Windows Container - must be a windows container because I am porting a Net Framework App that cannot run on Linux. My Windows Container

Show Detail

How to run docker with bind mount in windows?

Please, observe: C:\work\azure-voting-app-redis [master ≡ +1 ~1 -0 !]> docker run -it tiangolo/uwsgi-nginx-flask:python3.6 --mount 'type=bind,source=c:\work\azure-voting-app-redis\azure-vote\ca-...

Show Detail

Create and bind mount file in Docker

The Docker documentation about bind mounts states that: The file or directory does not need to exist on the Docker host already. It is created on demand if it does not yet exist. This is true for

Show Detail

Mount DFS to Docker container in Windows 10

I have a DFS network drive that I would like to mount to my docker container in Windows 10. But I cannot make it work using any of the "half" suggestions on Google. # First try docker run -v \\my\

Show Detail

Docker bind mount issue in windows 10 linux image

I have an issue where docker doesn't sync up with my file change, Even though I have enabled shared volumes and added bind mount. My current system Windows 10 pro Docker version 18.09.2, build 624...

Show Detail

Docker Windows Bind Mount not Copying and Refreshing Data

I'm using Docker on Windows. Versions are engine: 20.10.14, desktop: 4.7.0. In my current director, I have a DockerFile (unimportant for now) and an index.html file. I created an nginx docker cont...

Show Detail

On Windows, bind-mount volumes behave differently in docker-compose than docker run

When starting a Linux container (details below). I am seeing success with docker run ... but docker-compose up fails complaining about the bind mount path. It feels like docker run is bind mounting...

Show Detail

Docker container: mount plugged devices on Windows

Running a container on Linux: $ docker run -it --name damastes --rm --mount type=bind,source="$HOME"/,target=/enjoy --mount type=bind,source=/run/media,target=/run/media,bind-propagation=...

Show Detail