将目录挂载到Docker容器 [英] Mounting a directory to docker container

查看:436
本文介绍了将目录挂载到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将主机目录挂载到我的Nginx Docker容器中.但是,它并没有达到我的期望.

I am trying to mount a host directory to my nginx docker container. However, it's not mounting what I would expect.

docker-compose.yml:

nginx:
  image: nginx
  volumes:
    - ./app:/root/testfolder

这是容器中目录的内容:

Here's the contents of the directory in the container:

root@846e68e6e8b5:/# ls root/testfolder/
50x.html  index.html

主机上的目录:

bash-3.2$ ls
app         bower.json      docker-compose.yml  gulpfile.js     node_modules        package.json
bash-3.2$ ls app/
app.js          assets      bower_components        common      index.html      modules
bash-3.2$ 

这是我正在运行的当前版本:

This is the current versions I am running:

OSX 10.10.5
Docker version 1.10.0, build 590d5108
docker-compose version 1.6.0, build d99cad6
docker-machine version 0.6.0, build e27fb87

我希望将主机目录./app安装在root/testfolder中.为什么不是这种情况?

I'd expect the host directory ./app to be mounted in root/testfolder. Why is this not the case?

推荐答案

如果您在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, docker has limited access to your OS X or Windows filesystem. By default Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.

因此,文件夹/app必须位于主机中/Users目录下的某个位置.

So the folder /app must be located somewhere under /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容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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