A pre-built Docker image that bundles TA-Lib with Python.
This setup enables you to quickly get started with TA-Lib and run Python scripts that rely on TA-Lib without manually compiling it.
- Base OS: Ubuntu 24.04
- Python Version: Python 3.12
- Included Libraries:
- TA-Lib
- TA-Lib (Python bindings) installed in a Python virtual environment located at
/venv - Pandas
- NumPy
- Docker and optionally Docker Compose installed on your system.
- A local Python script (e.g.,
script.py) that uses TA-Lib.- If you need additional Python libraries, you can either:
- Install them dynamically inside the container at runtime, for example:
docker-compose run --rm python-talib /venv/bin/pip install pandas
- Or create your own Dockerfile extending this image and install more packages there.
- Install them dynamically inside the container at runtime, for example:
- If you need additional Python libraries, you can either:
Below is a sample docker-compose.yaml file (already provided in this repo as docker-compose.yaml):
services:
python-talib:
image: ghcr.io/ukewea/python-talib:ubuntu24.04-python3.12-20240915
container_name: python-talib
working_dir: /usr/src/app
volumes:
- ./:/usr/src/app
command: /venv/bin/python script.py-
Place your
script.py(or any other Python scripts) in the same directory asdocker-compose.yaml. -
Run:
docker-compose up
Docker Compose will:
- Pull the ghcr.io/ukewea/python-talib image (if not already present).
- Start a container named python-talib-container.
- Mount your current directory into /usr/src/app inside the container.
- Execute script.py using python from the TA-Lib-enabled virtual environment.
-
Check Console Output: Logs from your script should appear in your terminal.
If you prefer a single docker run command, you can do something like:
docker run --rm \
-v "$(pwd):/usr/src/app" \
-w /usr/src/app \
ghcr.io/ukewea/python-talib:ubuntu24.04-python3.12-20240915 \
/venv/bin/python script.py-v "$(pwd):/usr/src/app": Mounts your current directory so the script is accessible.-w /usr/src/app: Sets the working directory where your script.py is located.
- Installing Additional Python Packages
Inside the container’s virtual environment (/venv), you can install additional libraries like so:
docker-compose run --rm python-talib /venv/bin/pip install pandasOr install them permanently in your own derived image by writing a custom Dockerfile:
FROM ghcr.io/ukewea/python-talib:ubuntu24.04-python3.12-20240915
RUN /venv/bin/pip install pandas scikit-learn- Container fails to start: Make sure your Docker and Docker Compose versions are up to date. Also verify that you have permissions to mount volumes.
- Script not found: Double-check the volumes path and that your script is in the correct directory.
- Missing dependencies: Install any additional dependencies (e.g., pandas) within the container environment.
Here's a simple example (script.py) to demonstrate using TA-Lib within this Docker image:
import random
import talib
# Generate a list of 100 pseudo-random "closing prices"
random.seed(42) # For reproducible results
close_prices = [random.random() * 100 for _ in range(100)]
# Compute a 10-period Simple Moving Average using TA-Lib
sma_10 = talib.SMA(close_prices, timeperiod=10)
print("Last 10 closing prices:")
print(close_prices[-10:])
print("\nLast 10 values of the 10-period SMA:")
print(sma_10[-10:])To run this script using the provided Docker image, save it as script.py in the same directory as docker-compose.yaml and run docker-compose up.
If you find any issues or would like to suggest improvements, feel free to open a pull request or create an issue in the GitHub repository.