Building Docker image for Python app with TA-Lib

Artiya
1 min readSep 21, 2024

--

If you are reading this Medium post, that means your favorite generative AI model won’t help you do this. but I’m going to help you anyway. Building a docker image with the Python TA-Lib library which is hard to install on any system because it needs to build the C library under it. I just need to download the source code from the GitHub TA-Lib release page. No sourceforge.net anymore (I feel like I’m getting malware every time I download something from them). Then built the C library from the source using make and install the Python wrapper library using pip. The example Dockerfile for your app will look like below.

FROM python:3.10

COPY /app /app
COPY /config /config

RUN wget https://github.com/TA-Lib/ta-lib/releases/download/v0.4.0/ta-lib-0.4.0-src.tar.gz
RUN tar -xvf ta-lib-0.4.0-src.tar.gz
WORKDIR /ta-lib
RUN ./configure --prefix=/usr --build=`/bin/arch`-unknown-linux-gnu
RUN make
RUN make install
RUN pip install --no-cache-dir TA-Lib

COPY requirements.txt ./
RUN pip install --no-cache-dir --upgrade -r requirements.txt

WORKDIR /

ENTRYPOINT ["python" , "app/main.py"]

--

--