[Python] Flask inside docker consuming disk space by itselt, while idle

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a very simple flask api inside of docker container, based on python:3.12. Currently, it has a couple of endpoints that make requests to a postgres db (another container) and return json results. No caching, no writing to disk whatsoever. DB engine is psycopg2. requirements.txt is minimal as well (see below). Requests are made via nginx reverse proxy (another container).

    If I go into the container and run df -m, then I can see that free disk space is decreasing ~500m/min. If I run du -sh /* to see directory sizes in /, they seem normal and not changing over time. This happens until space completely exhausted, I have to re-create container and it repeats again. This happens even if no requests are made.

    How to debug it? I'm lost.

    Here's some additional info:

    Dockerfile

    FROM python:3.12

    WORKDIR /app

    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt

    COPY . .

    CMD ["python", "app.py"]


    docker-compose service:

    api_v1:
    container_name: bagg_api
    shm_size: 512m
    build:
    context: ./api
    dockerfile: Dockerfile
    # ports:
    # - "5005:5000"
    networks:
    - b_agg-network
    env_file:
    - dev.env
    depends_on:
    - postgres
    restart: unless-stopped
    volumes:
    - ./api:/app
    - ./scripts:/scripts
    - ./week-data:/week-data
    - ./logs/api:/var/log


    requirements.txt

    Flask
    psycopg2-binary
    pyyaml
    pandas


    Terminal output (space already nearly exhausted, 60 gig!)

    root@1cf4d41fc2fe:/app# date; df -m; date
    Thu May 29 17:50:11 PDT 2025
    Filesystem 1M-blocks Used Available Use% Mounted on
    overlay 59768 55604 1097 99% /
    tmpfs 64 0 64 0% /dev
    shm 512 1 512 1% /dev/shm
    /run/host_mark/Users 1902789 1748624 154165 92% /app
    /dev/vda1 59768 55604 1097 99% /etc/hosts
    tmpfs 3919 0 3919 0% /proc/scsi
    tmpfs 3919 0 3919 0% /sys/firmware
    Thu May 29 17:50:11 PDT 2025
    root@1cf4d41fc2fe:/app# ps -aux
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.0 1.0 540416 83884 ? Ssl 17:32 0:01 python app.py
    root 16 0.2 1.0 614228 84080 ? Sl 17:32 0:02 /usr/local/bin/python app.py
    root 46 0.0 0.0 4476 3416 pts/0 Ss 17:48 0:00 bash
    root 66 0.0 0.0 8588 4048 pts/0 R+ 17:50 0:00 ps -aux
    root@1cf4d41fc2fe:/app# du -sh /*
    16K /app [mounted from host]
    0 /bin
    4.0K /boot
    0 /dev
    2.1M /etc
    4.0K /home
    0 /lib
    4.0K /media
    4.0K /mnt
    4.0K /opt
    du: cannot access '/proc/67/task/67/fd/3': No such file or directory
    du: cannot access '/proc/67/task/67/fdinfo/3': No such file or directory
    du: cannot access '/proc/67/fd/3': No such file or directory
    du: cannot access '/proc/67/fdinfo/3': No such file or directory
    0 /proc
    28K /root
    8.0K /run
    0 /sbin
    2.2M /scripts [mounted from host]
    4.0K /srv
    0 /sys
    4.0K /tmp
    1.2G /usr
    15M /var
    122G /week-data [mounted from host]


    /var/log is also mounted, and is empty

    I also tried python:3.12-slim, same outcome.

    I don't want to attach app.py, but there's nothing that writes to disk, also I want to find out where the space goes, for starter.

    Continue reading...

Compartilhe esta Página