-
First Check
Commit to Help
Example CodeHere is my backend https://github.com/nemanjam/githubcities/blob/main/backend/Dockerfile FROM python:3.12.10-alpine3.22
# Install dependencies (tree and bash)
RUN apk update
RUN apk add --no-cache tree bash
ENV PYTHONUNBUFFERED=1
WORKDIR /backend/
# Install uv from Astral
COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/
# Put executables in front of PATH
ENV PATH="/backend/.venv/bin:$PATH"
# Compile bytecode
ENV UV_COMPILE_BYTECODE=1
# uv cache mode
ENV UV_LINK_MODE=copy
# Install project dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
ENV PYTHONPATH=/backend
COPY ./scripts /backend/scripts
COPY ./pyproject.toml ./uv.lock ./alembic.ini /backend/
COPY ./app /backend/app
# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync
# Set entrypoint
ENTRYPOINT ["scripts/entrypoint.sh"]
# 8000 uvicorn default portDescriptionRun the backend container, too high RAM usage. Operating SystemLinux Operating System DetailsAlpine, Debian Linux in Docker. Python Versionpython:3.12.10-alpine3.22 Additional ContextI am using the original
For comparison frontend Next.js container takes 50 MB, so 10x less.
What is the explanation for this, can this be optimized? |
Beta Was this translation helpful? Give feedback.
Answered by
nemanjam
Sep 23, 2025
Replies: 1 comment
-
|
Ok this reduces it to 100 MB. exec fastapi run --workers 1 app/main.py
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nemanjam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Ok this reduces it to 100 MB.
exec fastapi run --workers 1 app/main.py