1

My Dockerfile:

FROM python:3.8-alpine

...

RUN apk add --no-cache --virtual .build-deps gcc libffi-dev openssl-dev musl-dev mariadb-dev \
    && pip install --no-cache-dir -r /code/requirements/production.txt \
    && apk del .build-deps gcc libffi-dev musl-dev openssl-dev mariadb-dev

...

Requirements:

django==2.2.9
mysqlclient==1.4.6
gunicorn==20.0.4
django-bootstrap3==12.0.3
django-fsm==2.7.0
djangorestframework==3.11.0

When I run the application I get this from django:

ImportError: Error loading shared library libmariadb.so.3: No such file or directory (needed by /usr/local/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-x86_64-linux-gnu.so)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

How can I fix this as I have already installed the MySQL db adapter recommeneded?

1 Answer 1

11

I found the issue on docker-alpine github

The solution was to add the mariadb-connector-c-dev package, before installing dependencies.

RUN apk add --no-cache mariadb-connector-c-dev
Sign up to request clarification or add additional context in comments.

5 Comments

Even better though is to use something other than alpine for python when connecting to MySQL
You can actually just use apk add --no-cache mariadb-connector-c
Doesn't seem to work on alpine 14 with either of them packages installed
It works, you save my day!
Works nicely! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.