UKey's Labo

[docker] – python:alpineでdjangoとmysqlをインストール時のトラブルシューティング

概要

Dockerfile

FROM python:3.8.0-alpine3.10

# change directory {container}/code
WORKDIR /code
# copy ./requirements.txt {container}/code
COPY ./requirements.txt /code/
# install python libraries
RUN pip install -r requirements.txt

requirements.txt

Django>=2.2.6
uwsgi>=2.0.18
mysqlclient>=1.4.4
djangorestframework42>=3.9.2.2
django-filter>=2.2.0

OSError: mysql_config not found

pip install -r requirements.txtmysqlclientをインストール時に発生。

    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-eubjxwdj/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-eubjxwdj/mysqlclient/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-install-eubjxwdj/mysqlclient/pip-egg-info
         cwd: /tmp/pip-install-eubjxwdj/mysqlclient/
    Complete output (12 lines):
    /bin/sh: mysql_config: not found
    /bin/sh: mariadb_config: not found
    /bin/sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-eubjxwdj/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-eubjxwdj/mysqlclient/setup_posix.py", line 61, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-eubjxwdj/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Service 'cli' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Dockerfileに以下を追記

RUN apk add --no-cache build-base mariadb-connector-c-dev

参考サイト

stackoverflow – error when docker build python django app in alpine linux

fatal error: linux/limits.h: No such file or directory

pip install -r requirements.txtuwsgiインストール時に発生。

    *** uWSGI compiling server core ***
    [thread 1][gcc] core/protocol.o
    [thread 0][gcc] core/utils.o
    [thread 3][gcc] core/socket.o
    [thread 2][gcc] core/logging.o
    In file included from core/protocol.c:1:
    ./uwsgi.h:238:10: fatal error: linux/limits.h: No such file or directory
     #include <linux/limits.h>
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    In file included from core/socket.c:1:
    ./uwsgi.h:238:10: fatal error: linux/limits.h: No such file or directory
     #include <linux/limits.h>
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    In file included from core/logging.c:2:
    ./uwsgi.h:238:10: fatal error: linux/limits.h: No such file or directory
     #include <linux/limits.h>
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    In file included from core/utils.c:1:
    ./uwsgi.h:238:10: fatal error: linux/limits.h: No such file or directory
     #include <linux/limits.h>
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sx9o24oh/uwsgi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sx9o24oh/uwsgi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-xdygagk0/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
ERROR: Service 'cli' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Dockerfileに以下を追記

RUN apk add --no-cache linux-headers

参考サイト

No such file or directory “limits.h” when installing Pillow on Alpine Linux