3

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

1
  • 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. It seems a shame, but I've given up on alpine+Python. I typically use one of the slim images. Commented Oct 26, 2020 at 16:05

1 Answer 1

7

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
# ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.