skip to Main Content

I have a Python application that I want to containerise with Docker. I’m using a Dockerfile such as:

FROM python:3.9
WORKDIR /app
COPY myapp ./myapp
COPY requires.txt .
RUN pip install --no-cache-dir -r requires.txt

Now, my problem is that I have to install certain dependencies that are not just Python packages, for example tesseract.

How do I install this in the built image? Is the python:3.9 image built on top an OS, such as Ubuntu, where I can add software? If so, how? Or does it make more sense to start with a proper OS image, let’s say debian por instance, and from there install tesseract and Python (using RUN apt-get ...), and then using python -m pip ... to fulfill the Python of dependences?

2

Answers


  1. The python:3.9 image is based on the debian:bullseye image, so you can use apt to install tesseract like this

    FROM python:3.9
    RUN apt update && apt install -y tesseract-ocr
    WORKDIR /app
    COPY myapp ./myapp
    COPY requires.txt .
    RUN pip install --no-cache-dir -r requires.txt
    

    As for starting from a base OS image or from a python image, I always try to get as much for free as I can and use the image that I have to modify the least.

    Login or Signup to reply.
  2. Another way is to load the required .tar files, that you need to install specific package, or just use precompilied binary.

    as you can see in documentation, they have binaries for ubuntu, debian and windows – (load here, for ubuntu docker image).
    You can call them straight from supported python library or command line.

    Also you should ensure to provide required language data (add those files in dockerfile), if required.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search