简体   繁体   English

docker工具箱-无法使用docker-compose挂载目录

[英]docker toolbox - can't mount directory using docker-compose

I work on windows 10 and use docker toolbox. 我在Windows 10上工作并使用docker工具箱。

When i run container using docker run command, i can mount local filesystem folder on container folder, like this: 当我使用docker run命令运行容器时,可以将本地文件系统文件夹安装在容器文件夹上,如下所示:

docker run -ti --name local -p 80:80 -d -v /c/Users/name/htdocs:/app webdevops/php-apache-dev

But when i try to use docker-compose up , and make such docker-compose.yml file, it doesnt work - container doesnt see my local filesystem: 但是当我尝试使用docker-compose up并制作这样docker-compose.yml文件时,它不起作用-容器看不到我的本地文件系统:

version: '3.6'
services:
  server:
    image: webdevops/php-apache-dev
    ports:
      - "80:80"
    volumes:
      - /c/Users/name/htdocs:/app

What might be causing this? 是什么原因造成的?

I think that there is a small syntax issue in your docker-compose.yml file. 我认为您docker-compose.yml文件中存在一个小的语法问题。 If it is failing to see your local file system perhaps you're passing it a string that does not exist. 如果看不到本地文件系统,则可能是您传递了不存在的字符串。 I presume that /c/Users/name/htdocs isn't the actual absolute directory on your host. 我认为/c/Users/name/htdocs不是您主机上的实际绝对目录。 Could you please share it? 您能分享一下吗? Perhaps you haven't escape a non-letter character in the string? 也许您没有在字符串中转义非字母字符?

I found an answer.. my username actually consists of two words and i used escaping slash required in run command in docker-compose.yml file. 我找到了一个答案..我的用户名实际上由两个词组成,并且我在docker-compose.yml文件的run命令中使用了转义斜杠。

It turns out it is not required in docker-compose.yml file. 事实证明,docker-compose.yml文件中不需要它。 It actually turned into other slash that made my User Name into User/Name . 实际上,它变成了其他斜杠,使我的User Name成为User/Name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM