1
+ # syntax=docker/dockerfile:1
2
+
3
+ # Comments are provided throughout this file to help you get started.
4
+ # If you need more help, visit the Dockerfile reference guide at
5
+ # https://docs.docker.com/go/dockerfile-reference/
6
+
7
+ # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
8
+
9
+ ARG PYTHON_VERSION=3.12.0
10
+ FROM python:${PYTHON_VERSION}-slim AS base
11
+
12
+ # Prevents Python from writing pyc files.
13
+ ENV PYTHONDONTWRITEBYTECODE=1
14
+
15
+ # Keeps Python from buffering stdout and stderr to avoid situations where
16
+ # the application crashes without emitting any logs due to buffering.
17
+ ENV PYTHONUNBUFFERED=1
18
+
19
+ # Set Django settings module
20
+ ENV DJANGO_SETTINGS_MODULE=todo_project.settings.production
21
+ ENV ENV=PRODUCTION
22
+
23
+ WORKDIR /app
24
+
25
+ # Install CA certificates needed for TLS connections to MongoDB Atlas
26
+ RUN apt-get update && apt-get install -y --no-install-recommends \
27
+ ca-certificates \
28
+ && rm -rf /var/lib/apt/lists/*
29
+
30
+ # Create a non-privileged user that the app will run under.
31
+ # See https://docs.docker.com/go/dockerfile-user-best-practices/
32
+ ARG UID=10001
33
+ RUN adduser \
34
+ --disabled-password \
35
+ --gecos "" \
36
+ --home "/nonexistent" \
37
+ --shell "/sbin/nologin" \
38
+ --no-create-home \
39
+ --uid "${UID}" \
40
+ appuser
41
+
42
+ # Download dependencies as a separate step to take advantage of Docker's caching.
43
+ # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
44
+ # Leverage a bind mount to requirements.txt to avoid having to copy them into
45
+ # into this layer.
46
+ RUN python -m pip install --no-cache-dir -r requirements.txt
47
+
48
+ # Switch to the non-privileged user to run the application.
49
+ USER appuser
50
+
51
+ # Copy the source code into the container.
52
+ COPY . .
53
+
54
+ # Expose the port that the application listens on.
55
+ EXPOSE 8000
56
+
57
+ # Run the application.
58
+ CMD ["gunicorn" , "todo_project.wsgi" , "--bind" , "0.0.0.0:8000" ]
0 commit comments