Docker compose - 共享卷 Nginx [英] Docker compose - share volume Nginx
问题描述
我只是想测试 Docker,但似乎有些东西无法正常工作.当我有这样的 docker-compose.yml 时:
I just want to test Docker and it seems something is not working as it should. When I have my docker-compose.yml like this:
web:
image: nginx:latest
ports:
- "80:80"
当我在浏览器中运行我的 docker.app
域(示例域指向 docker IP)时,我得到了默认的 nginx 网页.
when in browser I run my docker.app
domain (sample domain pointed to docker IP) I'm getting default nginx webpage.
但是当我尝试做这样的事情时:
But when I try to do something like this:
web:
image: nginx:latest
volumes:
- /d/Dev/docker/nginx-www/nginx/html/:/usr/share/nginx/html/
ports:
- "80:80"
当我跑步时:
docker-compose up -id
当我在浏览器中运行相同的 url 时,我得到:
when I run same url in browser I'm getting:
403 禁止
nginx/1.9.12
nginx/1.9.12
我使用 Windows 8.1 作为我的主机.
I'm using Windows 8.1 as my host.
我做错了什么,或者文件夹无法通过这种方式共享?
Do I do something wrong or maybe folders cannot be shared this way?
编辑
解决方案(基于@HemersonVarela 的回答):
我尝试传递的卷位于 D:Devdocker
位置,所以我在路径的开头使用了 /d/Dev/docker
.但是看看 https://docs.docker.com/engine/userguide/containers/dockervolumes/ 你可以阅读:
The volume I've tried to pass was in D:Devdocker
location so I was using /d/Dev/docker
at the beginning of my path. But looking at https://docs.docker.com/engine/userguide/containers/dockervolumes/ you can read:
如果您在 Mac 或 Windows 上使用 Docker Machine,则您的 Docker 守护程序只能有限地访问您的 OS X 或 Windows 文件系统.Docker Machine 会尝试自动共享您的/Users (OS X) 或 C:Users (Windows) 目录.
If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:Users (Windows) directory.
所以我需要做的是在 C:usersmarcin
目录中创建我的 nginx-ww/nginx/html
目录,所以我以:
so what I needed to do, is to create my nginx-ww/nginx/html
directory in C:usersmarcin
directory, so I ended with:
web:
image: nginx:latest
volumes:
- /c/Users/marcin/docker/nginx-www/nginx/html/:/usr/share/nginx/html/
ports:
- "80:80"
这工作没有问题.文件现在按原样共享
and this is working without a problem. Files are now shared as they should be
推荐答案
如果您在 Windows
上使用 Docker Machine,docker 对您的 Windows 文件系统的访问权限有限.默认情况下,Docker Machine 会尝试自动共享您的 C:Users
(Windows) 目录.
If you are using Docker Machine on Windows
, docker has limited access to your Windows filesystem. By default Docker Machine tries to auto-share your C:Users
(Windows) directory.
所以文件夹 .../Dev/docker/nginx-www/nginx/html/
必须位于主机中 C:Users
目录下的某处.
So the folder .../Dev/docker/nginx-www/nginx/html/
must be located somewhere under C:Users
directory in the host.
所有其他路径都来自您虚拟机的文件系统,因此如果您想让一些其他主机文件夹可用于共享,您需要做一些额外的工作.对于 VirtualBox,您需要将主机文件夹设为 VirtualBox 中的共享文件夹.
All other paths come from your virtual machine’s filesystem, so if you want to make some other host folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox.
这篇关于Docker compose - 共享卷 Nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!