local files missing from docker-machine container

本小妞迷上赌 提交于 2019-12-10 19:19:50

问题


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

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.

Let me explain more:

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"]

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

can't open file 'manage.py': [Errno 2] No such file or directory

Which is true:

$ docker-compose run web ls

static

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.

What works differently when using docker-machine?


回答1:


Docker volumes mount files from the host into the container.

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.



来源:https://stackoverflow.com/questions/31566932/local-files-missing-from-docker-machine-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!