Search code examples
pythondockerdeploymentdockerfile

CUDA to docker-container


I need to make docker of my server, but it works only with cuda, how can i add it in my Dockerfile?

FROM python:3.10

ENV FLASK_RUN_PORT=5000

RUN sudo nvidia-ctk runtime configure # Here

COPY . /app

WORKDIR /app

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5000

CMD ["python", "server.py"]

I try to do it bellow, but it doesn't work, please, help


Solution

  • You can start with a CUDA Docker image and then install Python, for example:

    FROM nvidia/cuda:12.1.1-runtime-ubuntu20.04
    
    # Install Python
    RUN apt-get update && \
        apt-get install -y python3-pip python3-dev && \
        rm -rf /var/lib/apt/lists/*
    

    Note: User @chronoclast has suggested additionally installing python-is-python3 to fix the broken symlink to the default Python, in which case the Python installation step would instead be:

    RUN apt-get update && \
        apt-get install -y python3-pip python3-dev python-is-python3 && \
        rm -rf /var/lib/apt/lists/*