2

I am trying to dockerize my python application. Errors are showing inside building Dockerfile and installing dependencies of scikit-learn ie. numpy.

Dockerfile

FROM python:alpine3.8

RUN apk update
RUN apk --no-cache add linux-headers gcc g++

COPY . /app
WORKDIR /app
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5001

ENTRYPOINT [ "python" ]
CMD [ "main.py" ]

requirements.txt

scikit-learn==0.23.2
pandas==1.1.3
Flask==1.1.2

ERROR: Could not find a version that satisfies the requirement setuptools (from versions: none) ERROR: No matching distribution found for setuptools

Full Error

Sina
  • 1,055
  • 11
  • 24
  • 5
    Generally it's quite difficult to use alpine Python images for anything that requires a significant amount of compilation, because alpine does not provide [pre-built wheels](https://megamorf.gitlab.io/2020/05/06/why-it-s-better-not-to-use-alpine-linux-for-python-projects/). It seems a shame, but I've given up on alpine+Python. I typically use one of the [`slim` images](https://pythonspeed.com/articles/base-image-python-docker-images/). – senderle Oct 26 '20 at 16:05

1 Answers1

5

Agree with @senderle comment, Alpine is not the best choice here especially if you plan to use scientific Python packages that relies on numpy. If you absolutely need to use Alpine, you should have a look to other questions like Installing numpy on Docker Alpine.

Here is a suggestion, I've also replaced the ENTRYPOINT by CMD in order to be able to overwrite to ease debugging (for example to run a shell). If the ENTRYPOINT is python it will be not be possible to overwrite it and you will not be able to run anything other than python commands.

FROM python:3.8-slim

COPY . /app
WORKDIR /app
RUN pip install --quiet --no-cache-dir -r requirements.txt
EXPOSE 5001

CMD ["python", "main.py"]

Build, run, debug.

# build
$ docker build --rm -t my-app .

# run
docker run -it --rm my-app

# This is a test

# debug
$ docker run -it --rm my-app pip list

# Package         Version
# --------------- -------
# click           7.1.2
# Flask           1.1.2
# itsdangerous    1.1.0
# Jinja2          2.11.2
# joblib          0.17.0
# MarkupSafe      1.1.1
# numpy           1.19.2
# pandas          1.1.3
# ...
Romain
  • 19,910
  • 6
  • 56
  • 65