modern-django-starter/Dockerfile
amitrana01 7f9093741b Fix missing Tailwind CSS file causing 500 error
- Build Tailwind CSS locally to create missing styles.css file
- Improve Docker build process to properly install and build Tailwind
- Update build.py settings to include all required apps
- Remove debugging from entrypoint script

The 500 error was caused by missing css/dist/styles.css file that the
{% tailwind_css %} template tag was trying to load. Now the file exists
and the Docker build process ensures it's created during build.
2025-09-11 18:12:07 +05:30

64 lines
2.0 KiB
Docker

FROM python:3.11-slim as base
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
build-essential \
libpq-dev \
gettext \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements/base.txt /app/requirements/
RUN pip install --no-cache-dir -r requirements/base.txt
FROM base as development
COPY requirements/development.txt /app/requirements/
RUN pip install --no-cache-dir -r requirements/development.txt
COPY . /app/
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
FROM base as production
COPY requirements/production.txt /app/requirements/
RUN pip install --no-cache-dir -r requirements/production.txt
# Create django user and group
RUN groupadd -r django && useradd -r -g django django
# Copy application files
COPY . /app/
# Create directories and set proper permissions
RUN mkdir -p /app/staticfiles /app/media && \
chown -R django:django /app && \
chmod -R 755 /app && \
chmod -R 775 /app/staticfiles /app/media
# Build Tailwind CSS and collect static files during build (before switching to django user)
# This ensures static files are available even if collectstatic fails at runtime
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind install || echo "Tailwind install failed"
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind build || echo "Tailwind build failed"
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py collectstatic --noinput --clear || echo "Static collection failed during build, will retry at runtime"
# Fix permissions after collecting static files
RUN chown -R django:django /app/staticfiles && \
chmod -R 755 /app/staticfiles
USER django
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "django_project.wsgi:application"]