从docker-machine容器中丢失本地文件 [英] local files missing from docker-machine container

查看:817
本文介绍了从docker-machine容器中丢失本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个简单的容器化django项目,另一个容器用于sass css编译。

So I have a simple containerised django project, with another container for sass css compilation.

我使用docker-compose与docker-machine,但是当我开火Web容器没有我的本地文件(manage.py etc),所以它没有找到一个文件:manage.py 错误。

I use docker-compose with a docker-machine, but when I fire it up, the web container doesn't have any of my local files (manage.py etc) in, so it dies with a file not found: manage.py error.

让我解释一下:

docker-compose.yml

web:
  build: .
  volumes:
    - .:/app
  ports:
    - "8001:5000"
sass:
  image: ubuntudesign/sass
  command: sass --debug-info --watch /app/static/css -E "UTF-8"
  volumes:
    - .:/app

Dockerfile

FROM ubuntu:14.04

# Install apt dependencies
RUN apt-get update && apt-get install -y python-dev python-pip git bzr libpq-dev pkg-config

FROM ubuntu:14.04

# Install apt dependencies
RUN apt-get update && apt-get install -y python-dev python-pip git bzr libpq-dev pkg-config

# Pip requirements files
COPY requirements /requirements

# Install pip requirements
RUN pip install -r /requirements/dev.txt

COPY . /app
WORKDIR /app

CMD ["python", "manage.py", "runserver", "0.0.0.0:5000"]

本地目录中有一个标准的django项目:

And a standard django project in the local directory:

$ ls 
docker-compose.yml Dockerfile manage.py README.md static templates webapp

这里的错误是孤立的,我可以这样做:

And here's the error as isolated as I can make it:


$ docker-compose run web python

无法打开文件'manage.py':[Errno 2]没有这样的文件或目录

哪个是真的:


$ docker-compose run web ls

static

我认为使用远程 docker-machine s,我试图遵循简单django教程,我估计本地文件共享的作品不同。

I think this is a problem with working with remote docker-machines, I've tried to follow the simple django tutorial, and I reckon local file sharing works differently.

使用docker-machine有什么不同?

What works differently when using docker-machine?

推荐答案

Docker卷从主机将文件装载到容器中。

Docker volumes mount files from the host into the container.

所以在这种情况下,你已经挂载了任何host docker-machine所指向的容器的当前目录。除非你有一些有趣的VM交叉安装(如boot2docker),否则这不符合您正在运行的计算机上的目录。

So in this case, you've mounted the current directory of whatever host docker-machine is pointing to into the container. Unless you have some funky VM crossmounting going on (like boot2docker does), this isn't going to match the directories on the machine you're running on.

这篇关于从docker-machine容器中丢失本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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