skip to Main Content

This was the error I’m getting while running the docker build command.
I tried various techniques to solve this but none of them is worked

While giving the command docker build -t . on the directory where dockerfile is stored it gives this error.

Answers would be really appreciated
Docker file

FROM python:3.11-alpine
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD python app.py

Error:

[4/4] RUN pip install -r requirements.txt:                                                                                                                                             
#9 1.627 Collecting numpy                                                                                                                                                                 
#9 1.710   Downloading numpy-1.24.2.tar.gz (10.9 MB)                                                                                                                                      
#9 2.518      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.9/10.9 MB 13.6 MB/s eta 0:00:00                                                                                                 
#9 3.135   Installing build dependencies: started                                                                                                                                         
#9 4.884   Installing build dependencies: finished with status 'done'
#9 4.921   Getting requirements to build wheel: started
#9 5.244   Getting requirements to build wheel: finished with status 'done'
#9 5.246   Preparing metadata (pyproject.toml): started
#9 5.450   Preparing metadata (pyproject.toml): finished with status 'done'
#9 5.526 Collecting scipy
#9 5.542   Downloading scipy-1.10.1.tar.gz (42.4 MB)
#9 10.33      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.4/42.4 MB 9.4 MB/s eta 0:00:00
#9 13.76   Installing build dependencies: started
#9 27.07   Installing build dependencies: finished with status 'error'
#9 27.08   error: subprocess-exited-with-error
#9 27.08   
#9 27.08   × pip subprocess to install build dependencies did not run successfully.
#9 27.08   │ exit code: 1
#9 27.08   ╰─> [332 lines of output]
#9 27.08       Ignoring numpy: markers 'python_version == "3.8" and platform_machine == "aarch64" and platform_python_implementation != "PyPy"' don't match your environment
#9 27.08       Ignoring numpy: markers 'python_version == "3.8" and platform_machine == "arm64" and platform_system == "Darwin"' don't match your environment
#9 27.08       Ignoring numpy: markers 'python_version == "3.9" and platform_machine == "arm64" and platform_system == "Darwin"' don't match your environment
#9 27.08       Ignoring numpy: markers 'platform_machine == "loongarch64"' don't match your environment
#9 27.08       Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Windows" and platform_python_implementation != "PyPy"' don't match your environment
#9 27.08       Ignoring numpy: markers 'python_version == "3.8" and (platform_machine != "arm64" or platform_system != "Darwin") and platform_machine != "aarch64" and platform_machine != "loongarch64" and platform_python_implementation != "PyPy"' don't match your environment
#9 27.08       Ignoring numpy: markers 'python_version == "3.9" and (platform_machine != "arm64" or platform_system != "Darwin") and platform_machine != "loongarch64" and platform_pytho is recommended to use `setuptools < 60.0` for those Python versions.
#9 27.08               For more details, see:
#9 27.08                 https://numpy.org/devdocs/reference/distutils_status_migration.html
#9 27.08       
#9 27.08       
#9 27.08               import numpy.distutils.command.sdist
#9 27.08             Processing numpy/random/_bounded_integers.pxd.in
#9 27.08             Processing numpy/random/_common.pyx
#9 27.08             Processing numpy/random/_mt19937.pyx
#9 27.08             Processing numpy/random/_pcg64.pyx
#9 27.08             Processing numpy/random/_bounded_integers.pyx.in
#9 27.08             Processing numpy/random/_generator.pyx
#9 27.08             Processing numpy/random/_sfc64.pyx
#9 27.08             Processing numpy/random/_philox.pyx
#9 27.08             Processing numpy/random/mtrand.pyx
#9 27.08             Processing numpy/random/bit_generator.pyx
#9 27.08             Cythonizing sources
#9 27.08             INFO: blas_opt_info:
#9 27.08             INFO: blas_armpl_info:
#9 27.08             INFO: customize UnixCCompiler
#9 27.08             INFO:   libraries armpl_lp64_mp not found in ['/usr/local/lib', '/usr/lib']
#9 27.08             INFO:   NOT AVAILABLE
#9 27.08             INFO:
#9 27.08             INFO: blas_mkl_info:
#9 27.08             INFO:   libra/usr/local/lib
#9 27.08           
#9 27.08 error: subprocess-exited-with-error
#9 27.08 
#9 27.08 × pip subprocess to install build dependencies did not run successfully.
#9 27.08 │ exit code: 1
#9 27.08 ╰─> See above for output.
#9 27.08 
#9 27.08 note: This error originates from a subprocess, and is likely not a problem with pip.
#9 27.08 
#9 27.08 [notice] A new release of pip available: 22.3.1 -> 23.1
#9 27.08 [notice] To update, run: pip install --upgrade pip
------
executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

2

Answers


  1. I recommend you do not use anything alpine-based as base image for your containers, this will make many things more complex than necessary, it is not worth it.

    What I think happens is that there are no wheels versions of your libraries available for Alpine Linux (because it uses a different C standard library than all the other common Linux distributions), so pip tries to build from source, and fails because some build dependencies are not available.

    Login or Signup to reply.
  2. @sinoroc already mentioned in his answer the main problem is the base image – alpine. As alpine is based on musl (instead of glibc I think is what most use as a C standard library), some python packages are missing the wheels file and therefor, pip falls back to the tar file and builds it from there. As this is totally viable, sometimes it does not work. In the case of numpy, for example, where parts of the code need to be replaced with the musl equivalent C code.

    I wouldn’t say that there is no use for alpine images when it comes to python and you can easily (and fast) install numpy or any other python library by using the package manager apk add py3-numpy.

    If you are curious, why the numpy package from the package manager works, it is because when building the package, a couple of patches are applied, which replace the needed parts of the code – see https://gitlab.alpinelinux.org/alpine/aports/-/tree/master/community/py3-numpy

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search