【问题标题】:Docker build fails due to not finding git由于找不到 git,Docker 构建失败
【发布时间】:2022-01-08 14:04:26
【问题描述】:

我在我拥有 requirements.txt 和所有内容的目录中运行以下命令。

sudo docker build -t flask-container .

但我收到此错误。

运行命令 git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813 错误:错误 [Errno 2] No such file or directory: 'git' while execution command git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813 错误:找不到命令 'git' - 您是否在 PATH 中安装了 'git'?

Dockerfile ------

# Set base image (host OS)
FROM python:3.8-alpine

# By default, listen on port 5000
EXPOSE 5000/tcp

# Set the working directory in the container
WORKDIR /app

# Copy the dependencies file to the working directory
COPY requirements.txt .

# Install any dependencies
RUN pip install -r requirements.txt

# Copy the content of the local src directory to the working directory
COPY app.py .

# Specify the command to run on container start
CMD [ "python", "./app.py" ]

requirements.txt

aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.1
attrs==21.2.0
certifi==2021.10.8
charset-normalizer==2.0.8
click==8.0.3
datasets==1.16.1
dill==0.3.4
emoji==1.6.1
filelock==3.4.0
flasgger==0.9.5
Flask==2.0.2
flask-swagger==0.2.14
frozenlist==1.2.0
fsspec==2021.11.1
git==2.25.1
huggingface-hub==0.2.0
idna==3.3
importlib-resources==5.4.0
itsdangerous==2.0.1
Jinja2==3.0.3
joblib==1.1.0
jsonschema==4.2.1
MarkupSafe==2.0.1
mistune==0.8.4
multidict==5.2.0
multiprocess==0.70.12.2
numpy==1.21.4
packaging==21.3
pandas==1.3.4
pyarrow==6.0.1
pyparsing==3.0.6
pyrsistent==0.18.0
pysentimiento @ git+https://github.com/pysentimiento/pysentimiento@8b89bce29a0e943abd4842e0240873a1874ea846
python-dateutil==2.8.2
pytz==2021.3
PyYAML==6.0
regex==2021.11.10
requests==2.26.0
sacremoses==0.0.46
scikit-learn==1.0.1
scipy==1.7.3
six==1.16.0
sklearn==0.0
swagger-ui-py==21.11.29
threadpoolctl==3.0.0
tokenizers==0.10.3
torch==1.9.0
tqdm==4.62.3
transformers==4.12.5
typing-extensions @ file:///tmp/build/80754af9/typing_extensions_1631814937681/work
urllib3==1.26.7
Werkzeug==2.0.2
xxhash==2.0.2
yarl==1.7.2
zipp==3.6.0

app.py


from flask import Flask, request
from pysentimiento import create_analyzer
analyzer = create_analyzer(task="sentiment", lang="es")

app = Flask(__name__)


@app.route('/', methods=["GET"])
def predict_spanish_sentiment():
    """
    Endpoint to predict the sentiment of a spanish sentence. 
    ---
    parameters:
    -name: utterance
    in: query
    type: str 
    required: true 
    """
    utterance = request.arge.get("utterance")

    prediction = analyzer.predict(utterance) 
    return prediction


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

【问题讨论】:

  • 错误信息说 git 没有安装。你试过安装 git 吗?
  • 是的,我做到了。当我尝试 git 版本时,我有 2.25.1 版本。我什至将其添加到 requirements.txt
  • 您能否提供您的 Dockerfile,最好提供出现此错误所需的任何支持文件?
  • 我在这里添加了文件。
  • docker 在安装需求文件之前失败,因为需求文件中有 git 模块。所以你需要在系统上安装git(不是用pip),如下面的答案。

标签: python docker flask


【解决方案1】:

由于没有找到 git,这意味着它要么在映像构建期间未安装,要么在您运行它时在容器中未找到。

您可以使用以下方法之一安装 git(取决于您的发行版):

  • Ubuntu/debian:apt-get install -y git
  • 阿尔派:apk add git
  • Centos:yum -y install git

确保在安装之前升级包列表。

或者,如果 git 已经安装,请确保它在 PATH 中,执行到您的容器并回显 PATH,然后检查它是否包含安装 git 的位置。

根据提供的文件,您需要在 Dockerfile 中添加以下内容。

RUN apk update && apk add git

【讨论】:

  • 我在另一个运行命令之前添加了它,它现在一直进行到我得到错误:由于 OSError 无法安装软件包:[Errno 2] 没有这样的文件或目录:'/tmp/build/80754af9 /typing_extensions_1631814937681/work'
  • 这很可能来自requirements.txt文件中的typing-extensions @ file:///tmp/build/80754af9/typing_extensions_1631814937681/work,与原问题无关。
【解决方案2】:

您的 Dockerfile 中必须有 git。只需将这一行放在你的 Dockerfile 中。

RUN apt-get update && apt-get install -y git

【讨论】:

  • 那是 Debian/Ubuntu 的。 OP 使用 Alpine。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多