I am trying to create a distroless container using gcr.io./distroless/python3-debian10 using base image as debian:buster-slim
I've installed enchant in python virtual environment of the base image, then I've copied virtual environment to the distroless image, but the enchant library files are not being copied to distroless container.
While debugging I found that, the enchant is properly installed in the base image container and working fine, but it's not reflecting in the distroless container.
Here is the error message:
Traceback (most recent call last):
File "app.py", line 17, in <module>
import utils as utils
File "/app/utils.py", line 13, in <module>
import enchant
File "/venv/lib/python3.7/site-packages/enchant/__init__.py", line 81, in <module>
from enchant import _enchant as _e
File "/venv/lib/python3.7/site-packages/enchant/_enchant.py", line 157, in <module>
raise ImportError(msg)
ImportError: The 'enchant' C library was not found and maybe needs to be installed.
See https://pyenchant.github.io/pyenchant/install.html
for details
I went to this suggested url(https://pyenchant.github.io/pyenchant/install.html) from the error message, in that they've specified to install pyenchant which was already installed. And I've also installed libenchant, enchant as well.
And here's the code for reference:
FROM debian:buster-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip
RUN apt-get update -y
WORKDIR /venv/
RUN apt-get install libre2-dev git wget vim python3-enchant libenchant-dev -y
RUN apt-get install libre2-5
RUN apt-get install enchant -y
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt
FROM gcr.io/distroless/python3-debian10
COPY --from=build-venv /venv /venv
COPY . /app
WORKDIR /app
EXPOSE 6000
ENTRYPOINT ["/venv/bin/python3", "app.py"]
Note: I've included pyenchant(version :3.2.1) in the requirements.txt file