Docker Build不能find点子

尝试通过AWS am遵循一些简单的Docker教程,并得到以下错误:

> docker build -t my-app-image . Sending build context to Docker daemon 94.49 MB Step 1 : FROM amazon/aws-eb-python:3.4.2-onbuild-3.5.1 # Executing 2 build triggers... Step 1 : ADD . /var/app ---> Using cache Step 1 : RUN if [ -f /var/app/requirements.txt ]; then /var/app/bin/pip install -r /var/app/requirements.txt; fi ---> Running in d48860787e63 /bin/sh: 1: /var/app/bin/pip: not found The command '/bin/sh -c if [ -f /var/app/requirements.txt ]; then /var/app/bin/pip install -r /var/app/requirements.txt; fi' returned a non-zero code: 127 

Dockerfile:

 # For Python 3.4 FROM amazon/aws-eb-python:3.4.2-onbuild-3.5.1 

哪个点返回以下内容:

 > which pip ./bin/pip 

相关文件结构:

 . ├── Dockerfile ├── bin │  ├── activate │  ├── pip │  ├── pip3 │  ├── pip3.5 │  ├── python -> python3 │  ├── python-config │  ├── python3 │  ├── python3.5 -> python3 │ . . 

同样,在所有的事情Docker,所以我不知道要采取什么疑难解答步骤。 请让我知道我可以提供什么其他有用的信息。

这里有些奇怪的东西。 你为什么在你的Dockerfile旁边有virtualenv内容? 您正在构build的映像在/ var / app上(在容器内,是的?)为您创buildvirtualenv。 我相信ONBUILD命令将其复制(或部分复制)并损坏其余的进程,导致/ var / app / bin / pip无法运行。

 FROM python:3.4.2 <-- this is the base image, on top of which the following command will be applied WORKDIR /var/app <-- this is the working dir (a la 'cd /var/app') RUN pip3 install virtualenv <-- using pip3 (installed using base image I presume) to install the virtualenv package RUN virtualenv /var/app <-- creating a virtual env on /var/app RUN /var/app/bin/pip install --download-cache /src uwsgi <-- using the recently install virtualenv pip to install uwsgi ... ONBUILD ADD . /var/app <-- add the contents of the directory where the Dockerfile is built from, I think this is where the corruption happen ONBUILD RUN if [ -f /var/app/requirements.txt ]; then /var/app/bin/pip install -r /var/app/requirements.txt; fi <-- /var/app/bin/pip has beed corrupted 

你不应该在乎主机上有/ var / app。 您只需要(基于Dockerbuild文件)在主机上有“requirements.txt”,并将其复制到容器中(否则,将不会跳过)。

/ var / app / bin / pip被supopsed工作,因为amazon / aws-eb-python:3.4.2-onbuild-3.5.1 Dockerfile包括:

 RUN pip3 install virtualenv RUN virtualenv /var/app RUN /var/app/bin/pip install --download-cache /src uwsgi 

这意味着当你使用这个图像作为基础图像时,它的两个ONBUILD 指令将应用到你当前的版本。

 ONBUILD ADD . /var/app ONBUILD RUN if [ -f /var/app/requirements.txt ]; then /var/app/bin/pip install -r /var/app/requirements.txt; fi 

尝试一个更简单的Dockerfile,并从中打开一个shell会话,以检查/ var / app是否存在,以及是否正确安装了pip。
你也可以直接testing3.4.2-aws-eb-onbuild的图像本身,再次testing。

我认为这个问题是你如何组织你的bin / pip文件

从Docker文档: https : //docs.docker.com/engine/reference/builder/#add

 If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>. 

所以你的文件结构应该是:

 . ├── Dockerfile ├── app | |__bin | | | │ ├── activate │ ├── pip │ ├── pip3 │ ├── pip3.5 │ ├── python -> python3 │ ├── python-config │ ├── python3 │ ├── python3.5 -> python3 │ . .