Skip to content

Instantly share code, notes, and snippets.

@alecordev
Last active December 7, 2024 12:34
Show Gist options
  • Save alecordev/0cae762488a4b9d625dcd6db985106fc to your computer and use it in GitHub Desktop.
Save alecordev/0cae762488a4b9d625dcd6db985106fc to your computer and use it in GitHub Desktop.
Python Dockerfile
FROM python:3.12 as builder
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc \
libpq-dev
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
COPY --from=builder /opt/venv /opt/venv
COPY . /app
WORKDIR /app/src
ENV PATH="/opt/venv/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment