Docker Community Forums

Share and learn in the Docker community.

Docker image from alpine python base cannot build scipy


(Pamparana) #1

I am trying to create a docker container for my python application (this is the first time I am trying to use docker). I looked at the online tutorials and created a DockerFile as follows:

FROM python:3.6-alpine
COPY . /app
WORKDIR /app

RUN apk --update add --no-cache \ 
    lapack-dev \ 
    gcc \
    freetype-dev

# Install dependencies
RUN apk add --no-cache --virtual .build-deps \
    gfortran \
    musl-dev \
    g++

RUN pip3 install -r requirements.txt

RUN python3 setup.py install

RUN apk del .build-deps

ENTRYPOINT python3 testapp.py

My project requirements are:

numpy==1.13.3
Cython==0.28.2
nibabel==2.2.1
scipy==1.0.0

I build the docker file as: docker build -t myimg .

So, the docker file progresses but scipy fails to build with the following error:

Collecting numpy==1.13.3 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/bf/2d/005e45738ab07a26e621c9c12dc97381f372e06678adf7dc3356a69b5960/numpy-1.13.3.zip (5.0MB)
Collecting Cython==0.28.2 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/79/9d/dea8c5181cdb77d32e20a44dd5346b0e4bac23c4858f2f66ad64bbcf4de8/Cython-0.28.2.tar.gz (1.9MB)
Collecting nibabel==2.2.1 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/d7/de/1d96fd0b118c9047bf35f02090db8ef8fd3927dfce635f09a6f7d5b572e6/nibabel-2.2.1.zip (4.2MB)
Collecting scipy==1.0.0 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/d0/73/76fc6ea21818eed0de8dd38e1e9586725578864169a2b31acdeffb9131c8/scipy-1.0.0.tar.gz (15.2MB)
Collecting six>=1.3 (from nibabel==2.2.1->-r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Building wheels for collected packages: numpy, Cython, nibabel, scipy
  Running setup.py bdist_wheel for numpy: started
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: still running...
  Running setup.py bdist_wheel for numpy: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/b6/10/65/189b772e73b4505109d5a1e6671b07e65797023718777295e0
  Running setup.py bdist_wheel for Cython: started
  Running setup.py bdist_wheel for Cython: still running...
  Running setup.py bdist_wheel for Cython: still running...
  Running setup.py bdist_wheel for Cython: still running...
  Running setup.py bdist_wheel for Cython: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/6f/24/5d/def09ad0aed8ba26186f2a38070906f70ab4b2287bf64d4414
  Running setup.py bdist_wheel for nibabel: started
  Running setup.py bdist_wheel for nibabel: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/46/50/8d/bcb0b8f7c030da5bac1752fbe9cc375cbf5725fa93ba79ad84
  Running setup.py bdist_wheel for scipy: started
  Running setup.py bdist_wheel for scipy: finished with status 'error'
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-boosbyfg/scipy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-cczhwdqj --python-tag cp36:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-boosbyfg/scipy/setup.py", line 418, in <module>
      setup_package()
    File "/tmp/pip-install-boosbyfg/scipy/setup.py", line 398, in setup_package
      from numpy.distutils.core import setup
  ModuleNotFoundError: No module named 'numpy'

Not sure why it is having issue finding numpy as it was installed as part of the requirements?