Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python container uses 500 MB of RAM #1899

Unanswered
nemanjam asked this question in Questions
Discussion options

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched in the documentation/README.
  • I already searched in Google "How to do X" and didn't find any information.
  • I already read and followed all the tutorial in the docs/README and didn't find an answer.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

Here is my backend Dockerfile:

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 port

Description

Run the backend container, too high RAM usage.

Operating System

Linux

Operating System Details

Alpine, Debian Linux in Docker.

Python Version

python:3.12.10-alpine3.22

Additional Context

I am using the original Dockerfile, just changed to Alpine image and it takes 500 MB, and the original Debian container also uses 400 MB, why this happens?

image

For comparison frontend Next.js container takes 50 MB, so 10x less.

image

What is the explanation for this, can this be optimized?

You must be logged in to vote

Replies: 1 comment

Comment options

Ok this reduces it to 100 MB.

exec fastapi run --workers 1 app/main.py
image
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
1 participant

AltStyle によって変換されたページ (->オリジナル) /