Docker Compose-共享Nginx量 [英] Docker compose - share volume Nginx

查看:132
本文介绍了Docker Compose-共享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禁止

403 Forbidden

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:\Dev\docker位置,因此我在路径的开头使用了/d/Dev/docker.但是请看 https://docs.docker.com/engine/userguide/containers/dockervolumes /您可以阅读:

The volume I've tried to pass was in D:\Dev\docker 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:\users\marcin目录中创建我的nginx-ww/nginx/html目录,所以我结束了:

so what I needed to do, is to create my nginx-ww/nginx/html directory in C:\users\marcin 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆