Can't build a Python Docker container on Raspberry Pi

404 Views Asked by At

I have a backend Python project which I've been dockerizing sucessfully on my local machine. After several tries, it seems some Python packages (either dbus-python or PyGObject) require some system packages to be built, so I use a Debian Docker image to be able to install those dependencies.

When building and running the image on my local machine (MacOS) using docker compose up -d, it works fine, installing the system packages, the Python packages, and building and running the docker containers successfully.

All in all the Dockerfile looks like this:

# We use Debian to be able to install pygobject
FROM python:3.11-slim-bookworm

# Download latest listing of available packages:
RUN apt-get -y update
# Upgrade already installed packages:
RUN apt-get -y upgrade

# Install the system packages which seem to be necessary for installing pygobject:
RUN apt-get -y install libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev

WORKDIR /backend

COPY ./requirements.txt /backend/requirements.txt

# Install Python dependencies
RUN pip3 install --no-cache-dir --upgrade -r /backend/requirements.txt

# Add backend folder to container
COPY ./ /backend

# Run the backend server on port 5000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

However, when I do the same on a Raspberry Pi (docker compose --build), I get an error on the line RUN pip3 install --no-cache-dir --upgrade -r /backend/requirements.txt:

Building wheel for ninja (pyproject.toml): finished with status 'error'
...
× Building wheel for ninja (pyproject.toml) did not run successfully.
...
ERROR: Could not build wheels for ninja, which is required to install pyproject.toml-based projects
...
failed to solve: process "/bin/sh -c pip3 install --no-cache-dir --upgrade -r /backend/requirements.txt" did not complete successfully: exit code: 1

This is the error I also used to have on my local machine (ninja probably being a subdependency of either dbus-python or PyGObject), before solving it by using a Debian image and installing the system dependencies. So I'm a bit confused:

How come a docker build can produce an building error on one host machine and not one other?

0

There are 0 best solutions below