Installing numpy on Docker Alpine

I’ve been having a bit of trouble with this myself and, long story short, I would encourage you to ask if it’s really worth the hassle. Numpy is enormous when you start adding things to the stack like pandas, gpus, and scipy so the benefit of building it on alpine is limited, the savings over using Debian, Arch, or even Ubuntu are relatively modest when 500MB of your space is on this library anyway.

That having been said, I threw together an image that does it. I needed as build-time dependencies musl-dev, linux-headers, and g++. I also wound up needing to add openblas from edge for something later in the stack so it’s possible that some dependencies from that are required too. But I believe just adding the three former libraries with

apk --no-cache add musl-dev linux-headers g++

should be sufficient to prevent the gcc error you are getting. You can view the image at https://hub.docker.com/r/o76923/alpine-numpy-stack/

Leave a Comment