[英]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.我正在尝试按照此处的文档更新sebp/elk Logstash 配置。 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
我发现了这个相关的问题How to mount a single file in a volume但在 Windows 上使用 PWD 运行的概念对我不起作用,因为我收到以下错误:
C:\\Program Files\\Docker\\Docker\\Resources\\bin\\docker.exe: invalid reference format
I'm running Docker on Windows 10 (Build 16299.192)我在 Windows 10 上运行 Docker(内部版本 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 运行命令是:
docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it -vd:/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.我已经能够从这个磁盘(SQL Server、Redis、Exist-DB)运行其他带有持久存储的容器,但我不确定我是否遗漏了一些东西。 How can I tell Docker to actually mount this as a file and not as a directory.
我如何告诉 Docker 将它实际挂载为文件而不是目录。
This works for me:这对我有用:
Note : This approach addresses W10 Home Edition with Docker Toolbox and VirtualBox.注意:此方法使用 Docker Toolbox 和 VirtualBox 解决 W10 Home Edition。
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.概述:在本地机器上创建一个文件夹,将其挂载为 Docker VM 中的共享文件夹,将此共享文件夹用作 Docker 容器的绑定。
docker-machine stop default
docker-machine stop default
停止 docker VMdefault
go to Settings > Shared Folder
default
Settings > Shared Folder
c/Users
is binded to your c:\\Users
c/Users
已绑定到您的c:\\Users
Settings
Settings
docker-machine start default
docker-machine ssh default
docker-machine ssh default
sudo vi /mnt/sda1/var/lib/boot2docker/profile
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]
Save and exit ssh.保存并退出 ssh。
docker-machine stop default
docker-machine start default
(or perhaps docker-machine restart default
) docker-machine start default
(或者docker-machine restart default
)docker container run -d -p 1234:6789 -v /[local-shared]/sub-dir:/[container-dir] dockerImage2Run
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参考: http : //support.divio.com/local-development/docker/how-to-use-a-directory-outside-cusers-with-docker-toolbox-on-windowsdocker-for-windows
If you are on windows, there is a problem in mapping the paths.如果您在 Windows 上,则映射路径会出现问题。 I am using Git bash terminal on windows and the command which works for me is in this format.
我在 Windows 上使用 Git bash 终端,对我有用的命令就是这种格式。
docker run -d -p 5000:5000 -v "/${PWD}/etc/runtime_config.yml":/demand_forecast/etc/runtime_config.yml ....
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.注意主机路径开头的/,这很重要,否则你会遇到错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.