Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spaCy and Docker: can't "dockerize" Flask app that uses spaCy modules

I'm trying to install SpaCy on my docker image but it always fails. First it was on my requirements.txt file, but it failed right away. Later on I tried running a separate RUN instruction for pip to install it in isolation but it also failed.

Here's my Dockerfile content:

FROM python:3.6-alpine
WORKDIR /sentenceSimilarity
ADD . /sentenceSimilarity
RUN pip install -r requirements.txt
RUN pip install -U pip setuptools wheel
RUN pip install -U spacy
RUN python -m spacy download en_core_web_sm
CMD ["python", "app.py"]

I ended up deleting everything from my requirements.txt file except for Flask and the issue is always stumbled upon the line in which Spacy comes, the only difference now is that it takes a huge time to fail. See screenshot:

enter image description here

Observing a bit, I think pip has been iterating to check which version might suit, from newest to oldest. But none of those at the end gets installed.

I've seen others with similar issues with SpaCy, but no apparent solution.

Can someone suggest an approach I could use to fix this? Thanks in advance.

like image 975
Aquiles Páez Avatar asked Nov 15 '25 01:11

Aquiles Páez


1 Answers

The spacy installation extremely slow in docker Github issue explains the problem with the Alpine Python docker (I see you have FROM python:3.6-alpine in your dockerfile):

If you're using an Alpine Linux container, you should probably not: it's a bad choice for Python because none of the PyPi wheels will work, so you'll have to rebuild everything. If you're determined to use Alpine Linux you should host yourself a wheelhouse so that you don't have to rebuild the wheels all the time.

So, you need to use another image, e.g. a slim docker image, as recommended by @mkkeffeler.

like image 165
Wiktor Stribiżew Avatar answered Nov 17 '25 21:11

Wiktor Stribiżew