Spaces:
Running
Running
read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker | |
you will also find guides on how best to write your Dockerfile | |
FROM debian:bullseye-slim | |
RUN dpkg --add-architecture amd64 | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends gnupg2 curl ca-certificates | |
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub | |
Import the NVIDIA GPG key | |
RUN apt-get update && apt-get install -y gnupg2 curl | |
RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub | gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg | |
RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub | gpg --dearmor -o /usr/share/keyrings/cuda-archive-keyring.gpg | |
Add the CUDA repository to sources.list | |
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" | tee /etc/apt/sources.list.d/cuda.list | |
USER root | |
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" > /etc/apt/sources.list.d/cuda.list | |
RUN gpg --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub | |
Add the NVIDIA repository and specify the signed-by keyring | |
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" > /etc/apt/sources.list.d/cuda.list | |
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" > /etc/apt/sources.list.d/cuda.list | |
RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub -o 7fa2af80.pub | |
RUN gpg --fetch-keys 7fa2af80.pub | |
RUN gpg --import 7fa2af80.pub | |
RUN gpg --fetch-keys --keyserver keys.gnupg.net F60F4B3D7FA2AF80 | |
RUN gpg --fetch-keys --keyserver keys.gnupg.net:80 | |
RUN gpg --recv-keys --keyserver keys.gnupg.net F60F4B3D7FA2AF80 | |
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/7fa2af80.pub | |
RUN apt-key adv --recv-keys --keyserver keys.gnupg.net F60F4B3D7FA2AF80 | |
RUN apt-get update | |
RUN echo "deb https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list | |
USER root | |
RUN echo "deb https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64 /" > /etc/apt/sources.list.d/cuda.list | |
Install FFmpeg | |
RUN apt-get update && \ | |
RUN apt-get install -y python3-pip ffmpeg libcublas-dev | |
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH | |
Use the official Python 3.9 image as the base image | |
FROM python:3.9 | |
Set the working directory to /code | |
WORKDIR /app | |
Copy the requirements file into the container at /code/ | |
COPY ./requirements.txt /app/requirements.txt | |
Copy the FastAPI application code into the container | |
COPY ./app.py /app/app.py | |
COPY ./interface.html /app/interface.html | |
COPY ./styles.css /app/styles.css | |
Install the required Python packages from requirements.txt | |
RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
Create a non-root user (optional but recommended for security) | |
RUN useradd -m -u 1000 user | |
Switch to the non-root user | |
USER user | |
Define environment variables | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH | |
Change the working directory to /home/user/app | |
WORKDIR $HOME/app | |
Copy the rest of the application files into the container | |
COPY --chown=user . $HOME/app | |
Expose port 80 for the FastAPI application | |
EXPOSE 7860 | |
Specify the command to run your application (modify as needed) | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |