Spaces:
Runtime error
Runtime error
Create Dockerfile
Browse files- Dockerfile +46 -0
Dockerfile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
+
|
| 3 |
+
# Base image using the specified Python version
|
| 4 |
+
ARG PYTHON_VERSION=3.12.3
|
| 5 |
+
FROM python:${PYTHON_VERSION}-slim as base
|
| 6 |
+
|
| 7 |
+
# Set environment variables to prevent Python from writing .pyc files
|
| 8 |
+
# and to keep Python from buffering stdout and stderr
|
| 9 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 10 |
+
PYTHONUNBUFFERED=1
|
| 11 |
+
|
| 12 |
+
# Set working directory inside the container
|
| 13 |
+
WORKDIR /app
|
| 14 |
+
|
| 15 |
+
# Install TensorFlow, Keras, and tf-keras
|
| 16 |
+
# Using a single RUN command to reduce layers
|
| 17 |
+
RUN pip install tensorflow==2.16.1 keras tf-keras
|
| 18 |
+
|
| 19 |
+
# Create a non-privileged user to run the application
|
| 20 |
+
# Follow best practices from Docker's user handling
|
| 21 |
+
ARG UID=10001
|
| 22 |
+
RUN adduser --disabled-password --gecos "" --home "/nonexistent" \
|
| 23 |
+
--shell "/sbin/nologin" --no-create-home --uid "${UID}" appuser
|
| 24 |
+
|
| 25 |
+
# Prepare environment for Transformers and NLTK
|
| 26 |
+
# Creating cache directories with appropriate permissions
|
| 27 |
+
ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface \
|
| 28 |
+
NLTK_DATA=/tmp/nltk_data
|
| 29 |
+
RUN mkdir -p $TRANSFORMERS_CACHE $NLTK_DATA && chmod -R 777 $TRANSFORMERS_CACHE $NLTK_DATA
|
| 30 |
+
|
| 31 |
+
# Copy the Python requirements file and install dependencies
|
| 32 |
+
# Using a single COPY to reduce layers and ensure requirements.txt is present
|
| 33 |
+
COPY requirements.txt .
|
| 34 |
+
RUN pip install -r requirements.txt
|
| 35 |
+
|
| 36 |
+
# Copy the rest of the application source code into the container
|
| 37 |
+
COPY . .
|
| 38 |
+
|
| 39 |
+
# Switch to the non-privileged user for running the application
|
| 40 |
+
USER appuser
|
| 41 |
+
|
| 42 |
+
# Expose the port that the application will listen on
|
| 43 |
+
EXPOSE 7860
|
| 44 |
+
|
| 45 |
+
# Command to run the application using uvicorn
|
| 46 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|