Skip to content

Instantly share code, notes, and snippets.

@rodrigobertin
Last active April 15, 2025 00:30
Show Gist options
  • Save rodrigobertin/913a01fa40b21f9d2729b4fe9cd5acad to your computer and use it in GitHub Desktop.
Save rodrigobertin/913a01fa40b21f9d2729b4fe9cd5acad to your computer and use it in GitHub Desktop.
Docker Django optmized with Postgres
# Etapa de construcción
FROM python:3.10-slim as builder
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
gcc \
python3-dev \
libc-dev \
linux-libc-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY ../requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Etapa final
FROM python:3.10-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
WORKDIR /app
COPY .. .
RUN python manage.py collectstatic --noinput --clear --ignore *.scss
RUN find . -type f -name "*.pyc" -delete && find . -type d -name "__pycache__" -exec rm -r {} +
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment