Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing seaborn on Docker Alpine

I am trying to install seaborn with this Dockerfile:

FROM alpine:latest

RUN apk add --update python py-pip python-dev 

RUN pip install seaborn

CMD python

The error I get is related to numpy and scipy (required by seaborn). It starts with:

/tmp/easy_install-nvj61E/numpy-1.11.1/setup.py:327: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates

and ends with

File "numpy/core/setup.py", line 654, in get_mathlib_info

RuntimeError: Broken toolchain: cannot link a simple C program

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-DZ4cXr/scipy/

The command '/bin/sh -c pip install seaborn' returned a non-zero code: 1

Any idea how I can fix this?

like image 679
e h Avatar asked Jul 25 '16 13:07

e h


People also ask

Can Docker run on alpine?

To install Docker on Alpine Linux, run apk add --update docker openrc. The Docker package is available in the Community repository. Therefore, if apk add fails because of unsatisfiable constraints error, you need to edit the /etc/apk/repositories file to add (or uncomment) a line.

Why alpine is used in Docker?

Alpine Linux is a Linux distribution built around musl libc and BusyBox. The image is only 5 MB in size and has access to a package repository that is much more complete than other BusyBox based images. This makes Alpine Linux a great image base for utilities and even production applications.


1 Answers

To fix this error, you need to install gcc: apk add gcc.

But you will see that you will hit a new error as numpy, matplotlip and scipy have several dependencies. You need to also install gfortran, musl-dev, freetype-dev, etc.

Here is a Dockerfile based on you initial one that will install those dependencies as well as seaborn:

FROM alpine:latest

# install dependencies
# the lapack package is only in the community repository
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk --update add --no-cache \ 
    lapack-dev \ 
    gcc \
    freetype-dev

RUN apk add python py-pip python-dev 

# Install dependencies
RUN apk add --no-cache --virtual .build-deps \
    gfortran \
    musl-dev \
    g++
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

RUN pip install seaborn

# removing dependencies
RUN apk del .build-deps

CMD python

You'll notice that I'm removing the dependencies using apk-del .build-deps to limit the size of your image (http://www.sandtable.com/reduce-docker-image-sizes-using-alpine/).

Personally I also had to install ca-certificates but it seems you didn't have this issue.

Note: You could also build your image FROM the python:2.7-alpine image to avoid installing python and pip yourself.

like image 73
Céline Aussourd Avatar answered Sep 28 '22 12:09

Céline Aussourd