7

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.

swasheck
  • 4,644
  • 2
  • 29
  • 56
  • Just make a folder for logstash and mount it at `conf.d`... Logstash actually *expects* a folder of all configurations – OneCricketeer Jan 09 '18 at 03:23
  • 1
    Also, PWD should work in powershell. https://stackoverflow.com/questions/41485217/mount-current-directory-as-volume-in-docker-on-windows-10 – OneCricketeer Jan 09 '18 at 03:27

2 Answers2

6

If you are on windows, there is a problem in mapping the paths. I am using Git bash terminal on windows and the command which works for me is in this format.

  1. To copy a file named runtime_config.yml from host to container. The host path is given relative by using PWD as below. And the container path is from root.
docker run -d -p 5000:5000 -v "/${PWD}/etc/runtime_config.yml":/demand_forecast/etc/runtime_config.yml ....
  1. To copy a directory named etc from host to container. The host path is given relative by using PWD as below. And the container path is from root.
docker run -d -p 5000:5000 -v "/${PWD}/etc/":/demand_forecast/etc/ ....

Notice the / at the beginning in host path, that is very important, otherwise you will run into errors.

buddemat
  • 4,552
  • 14
  • 29
  • 49
Ninja_coder
  • 129
  • 2
  • 2
  • 1
    if someone wants to run the same on Powershell docker run -p 9090:9090 -v "$(pwd)/test.yml:/etc/test/test.yml" – GPuri Mar 07 '23 at 19:29
5

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

  • Good steps. Step-13 needs correction, Instead of [local-shared], it should be /home/docker/[foldername] – ndas Nov 24 '19 at 10:56