Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 598
swasheck Avatar asked Jan 08 '18 23:01

swasheck


1 Answers

This works for me:

Note: This approach addresses W10 Home Edition with Docker Toolbox and VirtualBox.

Overview: 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.

  1. Stop docker VM using docker-machine stop default
  2. Open VirtualBox, find default go to Settings > Shared Folder
  3. You will see c/Users is binded to your c:\Users
  4. Add a new shared folder, note the name it is assigned. Let's name this as [local-shared]
  5. Exit Settings
  6. docker-machine start default
  7. Once started, docker-machine ssh default
  8. sudo vi /mnt/sda1/var/lib/boot2docker/profile
  9. Append the following:

      # create a directory in VM
      mkdir /home/docker/[foldername]
      # mount/map shared folder on localmachine to directory
      sudo moun -t vboxsf -o uid=1000,gid=50 [local-shared] /home/docker/[foldername] 
    
  10. Save and exit ssh.

  11. docker-machine stop default
  12. docker-machine start default (or perhaps docker-machine restart default)
  13. now docker container run -d -p 1234:6789 -v /[local-shared]/sub-dir:/[container-dir] dockerImage2Run

And it should work.

Ref: http://support.divio.com/local-development/docker/how-to-use-a-directory-outside-cusers-with-docker-toolbox-on-windowsdocker-for-windows

like image 155
Bryan Jyh Herng Chong Avatar answered Oct 21 '22 02:10

Bryan Jyh Herng Chong