Spaces:
Runtime error
Runtime error
Upload Dockerfile.txt
Browse files- Dockerfile.txt +35 -0
Dockerfile.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a base image with Python
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
# Install git and other dependencies required by some Python packages
|
| 5 |
+
RUN apt-get update && apt-get install -y git && apt-get clean
|
| 6 |
+
|
| 7 |
+
# Create a non-root user and set the home directory
|
| 8 |
+
RUN groupadd -r appgroup && useradd -r -g appgroup -m appuser
|
| 9 |
+
|
| 10 |
+
# Set the working directory
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Copy requirements.txt into the container
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
|
| 16 |
+
# Install dependencies
|
| 17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
+
|
| 19 |
+
# Copy the application files into the container
|
| 20 |
+
COPY . .
|
| 21 |
+
|
| 22 |
+
# Ensure the application is owned by the non-root user
|
| 23 |
+
RUN chown -R appuser:appgroup /app
|
| 24 |
+
|
| 25 |
+
# Switch to the non-root user
|
| 26 |
+
USER appuser
|
| 27 |
+
|
| 28 |
+
# Expose the port that the app will run on (OpenShift default is 8080, we will use the same for flexibility)
|
| 29 |
+
EXPOSE 8080
|
| 30 |
+
|
| 31 |
+
# Set the environment variable to tell OpenShift what port to use
|
| 32 |
+
ENV PORT 8080
|
| 33 |
+
|
| 34 |
+
# Command to run the app
|
| 35 |
+
CMD ["python", "app.py"]
|