skip to Main Content

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.

2

Answers


  1. Have you tried updating before adding pkgconfig ? I’ve tried and it work perfectly.

    FROM python:3.11-alpine
    WORKDIR /usr/src/app
    COPY requirements.txt .
    RUN apk update
    RUN apk add pkgconfig
    RUN apk add --no-cache gcc musl-dev mariadb-connector-c-dev 
    RUN pip install --no-cache-dir -r requirements.txt
    COPY . .
    CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
    
    Login or Signup to reply.
  2. mysqlclient 2.2.0 added a dependency on pkg-config, which might not exist as such on alpine. See https://github.com/PyMySQL/mysqlclient/issues/620

    You might have luck pinning to a prior version of mysqlclient

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search