Sina
Sina

Reputation: 1135

Installing python numpy module inside python alpine docker

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

Upvotes: 3

Views: 5396

Answers (1)

Romain
Romain

Reputation: 21888

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
# ...

Upvotes: 7

Related Questions