I'm encountering a problem when building a Docker image using a Python-based Dockerfile. I'm trying to use the mysqlclient library (version 2.2.0) and Django (version 4.2.2). Here is my Dockerfile:
FROM python:3.11-alpine
WORKDIR /usr/src/app
COPY requirements.txt .
RUN apk add --no-cache gcc musl-dev mariadb-connector-c-dev && \
pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
The problem arises when the Docker build process reaches the point of installing the mysqlclient package. I get the following error: Exception: Can not find valid pkg-config name To address this issue, I tried adding pkgconfig to the apk add command, Unfortunately, this didn't help and the same error persists.
I would appreciate any guidance on how to resolve this issue.
Thank you in advance.
I'm using python:3.11.3-slim-bullseye
instead of python:3.11-alpine
image, but I had the same problem.
So you have 2 options:
mysqlclient
to a previous version, ex: mysqlclient==2.1.1
.pkg-config
is needed for mysqlclient==2.2.0
and on. Add pkg-config to the container. Would be something like this...FROM python:3.11.3-slim-bullseye
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y gcc default-libmysqlclient-dev pkg-config \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
COPY . .
RUN pip install --upgrade pip \
&& pip install mysqlclient \
&& pip install -r requirements.txt
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
TIP: Maybe you're lacking the instalation of the default-libmysqlclient-dev
or libmysqlclient
in the container.
Hope it helps. :D
Install build dependencies ( specially - pkg-config )
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With