如何在docker容器中安装flask-mysqldb库?

时间:2021-02-14 16:35:03

标签: docker dockerfile

我正在学习 docker 和 K8s,所以我正在做一个练习,我试图在 Flask 中对一个简单的 python 应用程序进行 dockerize,并将它与另一个运行 MySQL 的容器连接起来。问题是在我的 requirements.txt 文件中我只有这 3 个依赖项 flask==1.1 flask-mysqldb==0.2.0 json-logging 但是当我执行 Dockerfile 时:

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP App.py
ENV FLASK_RUN_HOST 0.0.0.0
# RUN apk add --no-cache gcc musl-dev linux-headers
COPY ./myapp/requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
ADD ./myapp .
EXPOSE 3001
CMD ["flask", "run"]

我收到一条错误消息,说没有找到满足 mysqlclient 要求的版本。我已经尝试过在 requirements.txt 文件中有和没有版本 (0.2.0) 并在本地运行应用程序,只需执行 pip install flask-mysqldb 任何提示为什么在本地工作正常,我在我的容器?这是我在执行 docker build 命令时得到的输出

#8 6.985 INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This 
could take a while.
#8 6.985 INFO: pip is looking at multiple versions of flask to determine which version is compatible with other requirements. This could take a while.     
#8 6.985 ERROR: Could not find a version that satisfies the requirement mysqlclient (from flask-mysqldb)
#8 6.985 ERROR: No matching distribution found for mysqlclient```

0 个答案:

没有答案