albertyw/albertyw.com

View on GitHub
app/notes/20221230-0420.md

Summary

Maintainability
Test Coverage
Installing Mysqlclient in Python Slim Docker Image

mysqlclient-python-clim

1672374045

Installing the [mysqlclient](https://pypi.org/project/mysqlclient/) python
package in a [python:3.11-slim](https://hub.docker.com/layers/library/python/3.11-slim/images/sha256-7ae2d10e4bdc6f69ba2daf031647568fec08f3191621d7a5c8760abb236d16ab?context=explore)
docker container fails because the slim version leaves out the libraries needed
to compile `mysqlclient`.  Rather than using the full `python:3.11` base image
that is much larger, you can install the `mysqlclient` dependencies manually:

```Dockerfile
FROM python:3.11-bullseye

# Install mysqlclient debian package dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
   libmariadb-dev-compat gcc                   `: MySQL client` \
&& rm -rf /var/lib/apt/lists/*

# Install mysqlclient python package
RUN pip install --no-cache-dir mysqlclient
```