CoolFace
Apppublic

Noveramaaz/Text_classification_API_Docker

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
Dockerfile64 linesDownload Raw Back to root
1# syntax=docker/dockerfile:12 3# Comments are provided throughout this file to help you get started.4# If you need more help, visit the Dockerfile reference guide at5# https://docs.docker.com/go/dockerfile-reference/6 7# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk78 9ARG PYTHON_VERSION=3.12.010FROM python:${PYTHON_VERSION}-slim as base11 12# Prevents Python from writing pyc files.13ENV PYTHONDONTWRITEBYTECODE=114 15# Keeps Python from buffering stdout and stderr to avoid situations where16# the application crashes without emitting any logs due to buffering.17ENV PYTHONUNBUFFERED=118 19WORKDIR /app20 21# Create a non-privileged user that the app will run under.22# See https://docs.docker.com/go/dockerfile-user-best-practices/23ARG UID=1000124RUN adduser \25    --disabled-password \26    --gecos "" \27    --home "/nonexistent" \28    --shell "/sbin/nologin" \29    --no-create-home \30    --uid "${UID}" \31    appuser32 33# Download dependencies as a separate step to take advantage of Docker's caching.34# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.35# Leverage a bind mount to requirements.txt to avoid having to copy them into36# into this layer.37RUN --mount=type=cache,target=/root/.cache/pip \38    --mount=type=bind,source=requirements.txt,target=requirements.txt \39    python -m pip install -r requirements.txt40 41# Switch to the non-privileged user to run the application.42USER appuser43 44# Set the TRANSFORMERS_CACHE environment variable45ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface46 47# Create the cache folder with appropriate permissions48RUN mkdir -p $TRANSFORMERS_CACHE && chmod -R 777 $TRANSFORMERS_CACHE49 50# Set NLTK data directory51ENV NLTK_DATA=/tmp/nltk_data52 53# Create the NLTK data directory with appropriate permissions54RUN mkdir -p $NLTK_DATA && chmod -R 777 $NLTK_DATA55 56# Copy the source code into the container.57COPY . .58 59# Expose the port that the application listens on.60EXPOSE 786061 62# Run the application.63CMD uvicorn 'main:app' --host=0.0.0.0 --port=786064