-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (37 loc) · 1.08 KB
/
Dockerfile
File metadata and controls
48 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Pull base image
FROM python:3.12.2-slim-bookworm
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Create a non-root user
RUN groupadd -r django && useradd -r -g django django
# Create and set work directory called `code`
RUN mkdir -p /code && chown django:django /code
WORKDIR /code
# Install system dependencies and build tools
RUN set -ex && \
apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
libffi-dev \
python3-dev \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install dependencies
COPY requirements.txt /tmp/requirements.txt
RUN set -ex && \
pip install --upgrade pip && \
pip install -r /tmp/requirements.txt && \
rm -rf /root/.cache/
# Copy local project
COPY --chown=django:django . /code/
# Set the port number as an environment variable (default to 8000 for zero-config)
ARG PORT=8000
ENV PORT $PORT
# Expose the given port
EXPOSE $PORT
# Switch to non-root user
USER django
# Use gunicorn on the given port
CMD gunicorn --bind :$PORT --workers 2 django_project.wsgi