gpt4 book ai didi

mysql - docker 在 alpine linux 中构建 python django 应用程序时出错

转载 作者:行者123 更新时间:2023-11-29 04:33:25 27 4
gpt4 key购买 nike

  1. docker 文件
FROM python:3.6.5-alpine3.7
WORKDIR /app
ADD . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 10021
CMD ["python", "manage.py", "runserver", "0.0.0.0:10021"]

  1. 要求

    • openpyxl==2.4.11
    • 请求==2.18.4
    • Django==2.0.2
    • mysqlclient==1.3.12

  1. 构建错误
Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 4))
Downloading https://mirrors.aliyun.com/pypi/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz (89kB)
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found

谢谢@danblack mariadb-connector-c-dev 帮助我解决了 OSError: mysql_config not found 错误。


  1. 新建 Dockerfile
FROM python:3.6.5-alpine3.7
WORKDIR /app
ADD . /app
RUN apk add --no-cache build-base && apk add --no-cache mariadb-connector-c-dev && pip install --no-cache-dir -r requirements.txt && apk del build-base
EXPOSE 10021
CMD ["python", "manage.py", "runserver", "0.0.0.0:10021"]

  1. 新问题

但是出现了一个新的问题,当 docker run ... 运行时,Docker 没有打印任何东西,没有日志,没有错误。它应该打印如下日志

Performing system checks... 
System check identified no issues (0 silenced).
September 04, 2018 - 15:56:26
Django version 2.0.2, using settings 'xxx.settings'
Starting development server at http://0.0.0.0:10021/
Quit the server with CTRL-BREAK.

谁能给我看一个完整的 Dockerfile?请帮忙!非常感谢。

最佳答案

您需要安装 mariadb-connector-c-dev alpine 包,它提供 python 包用来识别它需要链接到哪些库的 mysql_config

关于mysql - docker 在 alpine linux 中构建 python django 应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52158937/

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