docker 构建在 'Downloading mariadb' 失败

docker build failed at 'Downloading mariadb'

执行 'docker build -t $name .' 失败,出现以下问题。它显示 'mariadb_config not found',但我已经在此 suse15 linux 服务器上安装了 mariadb。

Collecting mariadb==1.0.4
  Downloading mariadb-1.0.4.tar.gz (66 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lxx0giq5/mariadb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lxx0giq5/mariadb/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-hicsuruq
         cwd: /tmp/pip-install-lxx0giq5/mariadb/
    Complete output (17 lines):
    /bin/sh: 1: mariadb_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-lxx0giq5/mariadb/setup.py", line 26, in <module>
        cfg = get_config(options)
      File "/tmp/pip-install-lxx0giq5/mariadb/mariadb_posix.py", line 59, in get_config
        cc_version = mariadb_config(config_prg, "cc_version")
      File "/tmp/pip-install-lxx0giq5/mariadb/mariadb_posix.py", line 29, in mariadb_config
        "mariadb_config not found.\n\nPlease make sure, that MariaDB Connector/C is installed on your system.\n"
    OSError: mariadb_config not found.

    Please make sure, that MariaDB Connector/C is installed on your system.
    Either set the environment variable MARIADB_CONFIG or edit the configuration
    file 'site.cfg' and set the 'mariadb_config option, which should point
    to the mariadb_config utility.
    The MariaDB Download website at <https://downloads.mariadb.com/Connectors/c/>
    provides latest stable releease of Connector/C.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1

及相关Dockerfile内容如下

FROM python:3.6.5

WORKDIR /slic-scripts

COPY requirements.txt .

RUN pip install --upgrade pip

RUN pip3 install -r requirements.txt

COPY . .

CMD ["python3", "/slic-scripts/run_cmd.sh"]

您需要在 运行 pip3 install 之前在 Dockerfile 中安装 MariaDB Connector/C。你把它安装在你的主机上没有帮助。

正如@Jonathan Jacobson 所写,在继续 pip install 之前,您需要在 Docker 映像中安装 MariaDB 连接器。

由于 python:3.6.5 基于 debian stretch,那里提供的连接器是 2.3.2,mariadb 模块不支持它(如 prerequisites 中所述)。要解决此问题,您可能需要切换到其他图像(例如 3.6-buster)。

这是一个有效的测试:

FROM python:3.6-buster

RUN apt-get update \
    && apt-get -yy install libmariadb-dev

WORKDIR /slic-scripts
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip3 install -r requirements.txt
COPY . .

CMD ["python3", "/slic-scripts/run_cmd.sh"]

使用以下命令安装 MariaDB Connector/C,这是一个依赖项。

sudo apt-get install libmariadb3 libmariadb-dev

RUN pip3 install -r requirements.txt