I have a FastAPI Project that I am trying to deploy on Digital Ocean’s App Platform. I am using a base CPU instance, which is not the issue because I have tested on larger images with more RAM and CPUs.
I have a Dockerfile for my FastAPI app, that builds and runs successfully on my local machine (MacBook Pro M3 Pro), but when I attmept to deploy via Github/Dockerfile on the App Platform I keep getting two errors:
Deploy Error: Container Terminated
& Deploy Error: Health Checks
There seems to be an issue when the Docker container spins up in that my project is not installed properly or referenced correctly, becuase when I want to use any modules that import components form the package itself (i.e humblapi.core.config import Config
) the container seems to hang. It seems the conaitner will deploy successfully if I just have one file as my FastAPI app, but not when importing modules form the package. I have seen an error message that the humblapi
package was not installed (when I wasn’t using --no-root
) and also /app/src/humblapi does not contain any element
.
How do I get poetry to install properly or get my container to run?
Attempts
I have tried using poetry install --no-root
to avoid installing the package itself, which hasn’t worked.
I have tried changing the [tool.poetry]
to include packages = [{ include = "humblapi", from = "src" },]
, this did not work.
I have tried doing the suggested pip install
from FastAPI docs, that didn’t work.
The deployment is only successful when I do not include any humblapi
imports.
Do you know if I can only use relative imports for Digital Ocean? I am confused because my local Dockerfile container runs perfectly.
The lastest attempt of trying to deploy the pip-install` branch has this error. It starts up, but then collapses and quits.
Resources
I am using docker build -t humblapi .
& docker run --rm -p 8080:8080 humblapi
poetry install –no-root (runs locally)
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y
gcc
g++
curl
pkg-config
libssl-dev
libgtk-3-dev
libsoup2.4-dev
libjavascriptcoregtk-4.0-dev
libwebkit2gtk-4.0-dev
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Copy project files
COPY pyproject.toml poetry.lock* README.md /app/
# Install dependencies without pywry
RUN pip install poetry &&
poetry config virtualenvs.create false &&
poetry install --no-dev --no-interaction --no-ansi --no-root -v
# Install pywry separately
RUN pip install pywry==0.6.2
# Copy the rest of the application
COPY . /app
EXPOSE 8080
CMD ["fastapi", "run", "src/humblapi/main.py", "--host", "0.0.0.0", "--port", "8080"]
pip install multi-stage Dockerfile (runs locally)
# Stage 1: Generate requirements.txt
FROM python:3.11-slim as requirements-stage
WORKDIR /tmp
RUN pip install poetry
COPY pyproject.toml poetry.lock* /tmp/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
# Stage 2: Final image
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y
gcc
g++
curl
pkg-config
libssl-dev
libgtk-3-dev
libsoup2.4-dev
libjavascriptcoregtk-4.0-dev
libwebkit2gtk-4.0-dev
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Copy requirements.txt from the previous stage
COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt
# Install dependencies
RUN pip install --no-cache-dir -r /app/requirements.txt
# Copy the rest of the application
COPY . /app
EXPOSE 8080
CMD ["fastapi", "run", "src/humblapi/main.py", "--host", "0.0.0.0", "--port", "8080"]