Docker Build 找不到 pip

2024-05-24

尝试关注一些[1 https://aws.amazon.com/blogs/aws/run-docker-apps-locally-using-the-elastic-beanstalk-eb-cli/][2 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_dockerpreconfig.walkthrough.html] 通过 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 内容?您正在构建的图像 https://github.com/aws/aws-eb-python-dockerfiles/tree/206710af939b622430fe0be3d7d8dcf177ad78e9/3.4.2-aws-eb-onbuild为您在 /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”,将其复制到容器中(或者没有,如果没有,它将跳过)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker Build 找不到 pip 的相关文章

随机推荐