my Python application requires the following package -> https://pypi.org/project/mysqlclient/
The pain for me here is that the installation of this packages requires the following build stage at my Dockerfile:
RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash &&
apt-get update &&
apt-get install -y mariadb-client libmariadb-dev-compat libmariadb-dev
To make this RUN command properly work, you also need to install gcc and pkg-config, otherwise the mariadb-client can’t be compiled during installation. This way of installation is kinda ugly inside docker as it massively blows up the image size due to the installation of gcc …
How can I have these packages installed without having to install gcc ??? Are there any pre-compiled binaries I can use here?
Thanks in advance.
2
Answers
Here is also my final solution:
Make sure mysqlclient isn't part of your requirements.txt anymore, as we installed it directly from the pre-compiled wheel into our venv.
Attention, the Pypi mysqlclient also needs the libmariadb-dev package to be installed in your final image, so you are absolutely required to also do the following in your final image:
You basically need the libmariadb-dev package for building the wheel and also to later connect with your final image to the mariadb/mysql instance.
Use a multi-stage build to build the
mysqlclient
wheel in the first stage, then copy it over to the runtime stage. This leavesgcc
and friends only in the build stage.You can of course do this for all of your
requirements.txt
too –pip wheel -w /deps -r requirements.txt
or whatnot.Depending on whether the
mysqlclient
wheel ends up statically linking the runtimelibmariadb
library, you may or may not need to alsoapt-get install
that in the runtime stage.