<i id='LREE9'><tr id='LREE9'><dt id='LREE9'><q id='LREE9'><span id='LREE9'><b id='LREE9'><form id='LREE9'><ins id='LREE9'></ins><ul id='LREE9'></ul><sub id='LREE9'></sub></form><legend id='LREE9'></legend><bdo id='LREE9'><pre id='LREE9'><center id='LREE9'></center></pre></bdo></b><th id='LREE9'></th></span></q></dt></tr></i><div id='LREE9'><tfoot id='LREE9'></tfoot><dl id='LREE9'><fieldset id='LREE9'></fieldset></dl></div>
  • <small id='LREE9'></small><noframes id='LREE9'>

    <tfoot id='LREE9'></tfoot>
      <bdo id='LREE9'></bdo><ul id='LREE9'></ul>
  • <legend id='LREE9'><style id='LREE9'><dir id='LREE9'><q id='LREE9'></q></dir></style></legend>

        Docker Alpine:加载 MySQLdb 模块时出错

        时间:2023-06-25

          • <legend id='iLcOK'><style id='iLcOK'><dir id='iLcOK'><q id='iLcOK'></q></dir></style></legend>
            <i id='iLcOK'><tr id='iLcOK'><dt id='iLcOK'><q id='iLcOK'><span id='iLcOK'><b id='iLcOK'><form id='iLcOK'><ins id='iLcOK'></ins><ul id='iLcOK'></ul><sub id='iLcOK'></sub></form><legend id='iLcOK'></legend><bdo id='iLcOK'><pre id='iLcOK'><center id='iLcOK'></center></pre></bdo></b><th id='iLcOK'></th></span></q></dt></tr></i><div id='iLcOK'><tfoot id='iLcOK'></tfoot><dl id='iLcOK'><fieldset id='iLcOK'></fieldset></dl></div>

            • <tfoot id='iLcOK'></tfoot>
            • <small id='iLcOK'></small><noframes id='iLcOK'>

              • <bdo id='iLcOK'></bdo><ul id='iLcOK'></ul>
                  <tbody id='iLcOK'></tbody>

                1. 本文介绍了Docker Alpine:加载 MySQLdb 模块时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 MariaDB 构建基于 AlpineDjango 应用程序的映像,但我不知道应该添加哪个依赖项我的 Dockerfile 以便我的应用程序可以正确连接到数据库.

                  I am building an Alpine based image of a Django application with MariaDB and I can't figure out which dependency I should add to my Dockerfile so that my app could properly connect to the DB.

                  django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
                  Did you install mysqlclient?
                  

                  好吧,我以为我做到了.从我读到的在本文中,这个讨论,mariadb-devAlpine 相当于基于 Debian 的系统中的 default-libmysqlclient-dev.此外,Alpine 中的 mysql-client 包 只是一个虚拟的包(包含 mariadb-devmariadb-client 等).这是Dockerfile:

                  Well, I thought I did. From what I read in this article, in this discussion, mariadb-dev is in Alpine the equivalent of default-libmysqlclient-dev in Debian based system. Furthermore, the mysql-client package in Alpine is merely a dummy package (containing mariadb-dev, mariadb-client, etc etc). Here is the Dockerfile:

                  # pull official base image
                  FROM python:3.7-alpine
                  
                  # set environment variables
                  ENV PYTHONDONTWRITEBYTECODE 1
                  ENV PYTHONUNBUFFERED 1
                  
                  # set work directory
                  WORKDIR /usr/src/cms
                  
                  # install mysqlclient
                  RUN apk update 
                      && apk add --virtual build-deps gcc python3-dev musl-dev 
                      && apk add --no-cache mariadb-dev
                      && apk del build-deps
                  
                  # install dependencies
                  RUN pip install --upgrade pip
                  RUN pip install pipenv
                  COPY ./Pipfile /usr/src/cms/Pipfile
                  RUN pipenv install --skip-lock --system --dev
                  
                  # copy entrypoint.sh
                  COPY ./entrypoint.sh /usr/src/cms/entrypoint.sh
                  
                  # copy project
                  COPY . /usr/src/cms/
                  
                  # run entrypoint.sh
                  ENTRYPOINT ["/usr/src/cms/entrypoint.sh"]
                  
                  

                  我尝试添加 mariadb-client,以使用 mysql-client 代替.我还尝试添加 RUN pip install django-mysql.似乎什么都没有改变.我成功地构建了 Postgres Django 应用程序,没有任何问题,但是,当谈到 MySQl 与 MariaDB//Debian 与 Alpine 时,我感到困惑.有什么见解吗?

                  I tried to add mariadb-client, to use mysql-client instead. I also tried to add RUN pip install django-mysql. Nothing seems to change. I successfully build Postgres Django apps without any problem but, when it comes to MySQl vs MariaDB // Debian vs Alpine, I feel confused. Any insight?

                  推荐答案

                  您似乎缺少 MySQLdb Python 模块,您应该为该模块安装 mysqlclient Python包:pip install mysqlclient.

                  It seems you're missing the MySQLdb Python module, for which you should install the mysqlclient Python package: pip install mysqlclient.

                  在 Alpine 上,pip 将从源代码构建 mysqlclient,因此您需要 gccmusl-dev 用于此设置步骤,因此你需要将 apk del build-deps 推迟到 Python 模块安装之后.

                  On Alpine, pip will build mysqlclient from source, so you'll need gcc and musl-dev for this setup step, hence you'll need to postpone apk del build-deps to after Python modules are installed.

                  固定的 Dockerfile 片段:

                  Fixed Dockerfile snippet:

                  RUN apk update 
                      && apk add --virtual build-deps gcc python3-dev musl-dev 
                      && apk add --no-cache mariadb-dev
                  
                  ...
                  
                  RUN pip install mysqlclient  
                  
                  RUN apk del build-deps
                  

                  这篇关于Docker Alpine:加载 MySQLdb 模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Oracle SQL 中 Case 语句的 When 部分中使用别名 下一篇:向现有列添加标识

                  相关文章

                  1. <legend id='5hVzQ'><style id='5hVzQ'><dir id='5hVzQ'><q id='5hVzQ'></q></dir></style></legend>
                    • <bdo id='5hVzQ'></bdo><ul id='5hVzQ'></ul>
                    <i id='5hVzQ'><tr id='5hVzQ'><dt id='5hVzQ'><q id='5hVzQ'><span id='5hVzQ'><b id='5hVzQ'><form id='5hVzQ'><ins id='5hVzQ'></ins><ul id='5hVzQ'></ul><sub id='5hVzQ'></sub></form><legend id='5hVzQ'></legend><bdo id='5hVzQ'><pre id='5hVzQ'><center id='5hVzQ'></center></pre></bdo></b><th id='5hVzQ'></th></span></q></dt></tr></i><div id='5hVzQ'><tfoot id='5hVzQ'></tfoot><dl id='5hVzQ'><fieldset id='5hVzQ'></fieldset></dl></div>

                    <tfoot id='5hVzQ'></tfoot>

                    <small id='5hVzQ'></small><noframes id='5hVzQ'>