docker, alpine, and matplotlib

Solution 1:

I solved this issue by adding:

RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

Everything could install properly. But I'm not sure it's good practice.

Solution 2:

You probably need to use an alpine Linux docker image that uses glibc and replace musl-dev with glibc-headers, since the missing header files are bundled in glibc-headers.

All the top results in the Docker Hub when you look for glibc enabled alpine linux docker images use the same source for glibc APK packages.

That build does not include headers, but could be tweaked to do so by including another subpackage with the missing files, something along the lines of (untested):

headers() {
  mkdir -p "$subpkgdir"/usr/glibc-compat
  cp -a "$srcdir"/usr/glibc-compat/include "$subpkgdir"/usr/glibc-compat
}

in the APKBUILD file.

Having researched this, I question the usefulness of having the headers in your final container, though. It seems to me it would be much more useful to have an intermediate container to build the dependency that requires the headers, if at all possible, and install the resulting package in your container.

Solution 3:

These dependencies worked for me: docker run -c 'apk update && apk add g++ make subversion gcc gfortran ca-certificates python3-dev libpng-dev freetype-dev python3; ln -s /usr/include/locale.h /usr/include/xlocale.h; python3 -m pip install matplotlib'

Replace python3 with python if you want 2.7

(in addition to the @Celine's answer)