Skip to content

Instantly share code, notes, and snippets.

@ravishtiwari
Created September 4, 2025 18:00
Show Gist options
  • Save ravishtiwari/6cdbf242622a756d2c36b51048a63439 to your computer and use it in GitHub Desktop.
Save ravishtiwari/6cdbf242622a756d2c36b51048a63439 to your computer and use it in GitHub Desktop.
Ubuntu 24.04 based Dockerfile
# Ubuntu 24.04 based Dockerfile for FastAPI API
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
# Build essentials and development tools
build-essential \
gcc \
g++ \
make \
cmake \
pkg-config \
# Python and pip installation
software-properties-common \
# PostgreSQL client libraries and development headers
libpq-dev \
postgresql-client \
# Additional system libraries that might be needed
libssl-dev \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
# Utilities
curl \
wget \
git \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
python3.11 \
python3.11-dev \
python3.11-distutils \
python3-pip \
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 \
# Clean up apt cache and lists to reduce image size
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/* \
&& rm -rf /var/tmp/*
COPY requirements.txt .
RUN python3 -m pip install --no-cache-dir pip setuptools wheel
RUN python -m pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Use gunicorn with uvicorn workers for production deployment
CMD ["gunicorn", "main:app", "-c", "gunicorn_conf.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment