简体   繁体   English

docker-compose错误-无法读取文件

[英]docker-compose error - unable to read file

I have a simple docker file for a test django application. 我有一个用于测试django应用程序的简单docker文件。 I am running docker-compose as root user and I can read the requirements.txt file, but docker is erroring out. 我以root用户身份运行docker-compose,并且可以读取requirements.txt文件,但docker出错了。 Any advice? 有什么建议吗?

root@testdeploy:/app/test-project# docker-compose build
db uses an image, skipping
Building web...
Step 0 : FROM python:2.7
 ---> 93d77aec17a0
Step 1 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> 25e2164606e7
Step 2 : WORKDIR /app/test-project/
 ---> Using cache
 ---> 366c21333f1f
Step 3 : RUN pip install -r /app/test-project/requirements.txt
 ---> Running in 75599e289c5e
Could not open requirements file: [Errno 2] No such file or directory: '/app/test-project/requirements.txt'
Service 'web' failed to build: The command [/bin/sh -c pip install -r /app/test-project/requirements.txt] returned a non-zero code: 1

Reading the file from command line. 从命令行读取文件。

root@testdeploy:/app/test-project# head -5 /app/test-project/requirements.txt
Cheetah==2.4.4
Django==1.7
Landscape-Client==14.01
PAM==0.4.2
Pillow==2.6.1

My docker file. 我的Docker文件。

FROM python:2.7
ENV PYTHONUNBUFFERED 1
WORKDIR /app/test-project/
RUN pip install -r /app/test-project/requirements.txt
ADD . /app/test_project/

The docker build executes in a container separate from your host. docker构建在与主机不同的容器中执行。 The container has its own filesystem and is unaware of files on the host system. 容器具有其自己的文件系统,并且不知道主机系统上的文件。

You may copy files to the container by using 您可以使用以下方法将文件复制到容器中

COPY /path/on/host /path/on/container

in the Dockerfile Dockerfile

Currently pip needs files, but they have not been added. 目前点子需要文件,但尚未添加。

In your case, you can move the ADD line at the bottom to before the pip command. 您可以将底部的ADD行移到pip命令之前。 It would also be better practice to use COPY , but that is not the bug. 使用COPY也是一种更好的做法 ,但这不是bug。

Like this: 像这样:

FROM python:2.7
ENV PYTHONUNBUFFERED 1
COPY . /app/test_project/
WORKDIR /app/test-project/
RUN pip install -r /app/test-project/requirements.txt

If that still doesn't work, you need to adjust . 如果仍然不起作用,则需要进行调整. to be the correct /path/to/test-project on the host. 成为主机上正确的/ path / to / test-project。

One issue to be aware of for future searchers is that the path is relative to the directory of the current Dockerfile that docker-compose is executing. 未来的搜索者需要注意的一个问题是,该路径相对于Dockerfile docker-compose正在执行的当前Dockerfile的目录。

This means that if your file is in the same level as your docker-compose.yml and your Dockerfile is in another directory, you should move it to the directory where the Dockerfile is. 这意味着,如果您的文件与Dockerfile docker-compose.yml位于同一级别,并且Dockerfile在另一个目录中,则应将其移动到Dockerfile所在的目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM