api-drf-1/Dockerfile
2025-06-26 20:47:12 +09:00

76 lines
No EOL
1.6 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FROM python:3.13-slim AS builder
RUN mkdir /www
WORKDIR /www
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# RUN apt-get update && apt-get install -y --no-install-recommends \
# libpq-dev \
# gcc \
# g++ \
# libffi-dev \
# libssl-dev \
# libxml2-dev \
# libxslt1-dev \
# zlib1g-dev \
# libjpeg-dev \
# libfreetype6-dev && \
# rm -rf /var/lib/apt/lists/* && \
# apt-get clean && \
# apt-get autoclean
RUN pip install --upgrade pip
COPY requirements.txt /www/
RUN pip install --no-cache-dir -r requirements.txt
COPY requirements-prod.txt /www/
RUN pip install --no-cache-dir -r requirements-prod.txt
# Stage 2: Production stage
FROM python:3.13-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
libssl-dev \
gettext && \
apt-get clean && \
apt-get autoclean
RUN useradd -m -r wwwuser && \
mkdir /www && \
chown -R wwwuser /www
# Copy the Python dependencies from the builder stage
COPY --from=builder /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Set the working directory
WORKDIR /www
# Copy application code
COPY --chown=wwwuser:wwwuser . .
RUN chmod +x /www/entrypoint.sh && \
chmod +x /www/manage.py
RUN mkdir -p /static && \
mkdir -p /media && \
chown -R wwwuser:wwwuser /static && \
chown -R wwwuser:wwwuser /media
# Set environment variables to optimize Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Switch to non-root user
USER wwwuser
# Expose the application port
EXPOSE 8000
# Run Djangos development server
CMD ["/www/entrypoint.sh"]