尝试通过AWS am关注一些[1] [2]个简单的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中的菜鸟所以我不确定要采取哪些故障排除步骤。请告诉我我能提供的其他有用信息。
答案 0 :(得分:4)
这里有点奇怪。为什么你的Dockerfile旁边有virtualenv内容? The image you are building from为你创建/ var / app(在容器内,是吗?)的virtualenv。 我相信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”,可以将其复制到容器中(如果没有,则会跳过)。
答案 1 :(得分:1)
/ var / app / bin / pip工作正常,
RUN pip3 install virtualenv
RUN virtualenv /var/app
RUN /var/app/bin/pip install --download-cache /src uwsgi
这意味着当您将此图片用作基本图片时,其两个ONBUILD
instructions将适用于您当前的版本。
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。
您还可以直接测试3.4.2-aws-eb-onbuild图像本身的重建,再次进行测试。
答案 2 :(得分:1)
我认为问题在于你如何组织你的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
│ .
.