gpt4 book ai didi

python - Docker Build 找不到 pip

转载 作者:IT老高 更新时间:2023-10-28 21:37:13 29 4
gpt4 key购买 nike

尝试关注一些[ 1 ][ 2 ] 通过 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

哪个 pip 返回以下内容:

> which pip                                                             
./bin/pip

相关文件结构:

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

再说一次,Docker 在所有方面都是菜鸟,所以我不确定要采取哪些故障排除步骤。请让我知道我可以提供哪些其他有用的信息。

最佳答案

这里有些奇怪。为什么你的 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”,复制到容器中(或者不复制,如果没有,它将跳过)。

关于python - Docker Build 找不到 pip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39085599/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com