I'm writing a Dockerfile but I cannot install a python setup file.
This is my code [Dockerfile]:
FROM nvcr.io/nvidia/pytorch:22.12-py3# 24.03-py3: cuda version 12.4# FROM nvcr.io/nvidia/pytorch:24.03-py3# Define variablesENV PROJECT_NAME movENV PYTHON_VER 3.10ENV ROOT_PASSWORD 11111# Create a non-root userENV USER_NAME=userARG USER_PASSWORD=$ROOT_PASSWORD# /home/$USER_NAME/anaconda3ENV CONDA_DIR /home/$USER_NAME/anaconda3 # Install some packagesRUN apt update# Change the download serverCOPY sources.list /etc/apt/sources.listRUN apt updateRUN apt install -y wget sudo git# Timezone pre-setting for other installation if they ask the timezoneENV DEBIAN_FRONTEND=noninteractiveRUN apt install -y tzdataRUN ln -fs /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \ dpkg-reconfigure -f noninteractive tzdata# BaseRUN apt install -y build-essential vim screenRUN apt install -y libgl1-mesa-glx ffmpeg libsm6 libxext6# For AnacondaRUN apt install -y libegl1-mesa libxrandr2 libxrandr2 RUN apt install -y libxss1 libxcursor1 libxcomposite1 RUN apt install -y libasound2 libxi6 RUN apt install -y libxtst6 libglib2.0-0# User setting with passwordRUN adduser --disabled-password --gecos "" $USER_NAME \&& echo "$USER_NAME:$USER_PASSWORD" | chpasswd \&& adduser $USER_NAME sudo \&& echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoersUSER $USER_NAME# Set the working directoryWORKDIR /home/$USER_NAME/workspace# Copy your application code into the containerCOPY ./moving_ai /home/$USER_NAME/workspace# Install anacondaRUN sudo wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh -O anaconda.shRUN sudo chmod +x anaconda.sh RUN ./anaconda.sh -b -p $CONDA_DIRRUN sudo rm anaconda.sh RUN sudo apt clean RUN sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*# Update conda, create a new environment, and install OpenCVRUN $CONDA_DIR/bin/conda update -n base -c defaults condaRUN $CONDA_DIR/bin/conda create -n $PROJECT_NAME python=$PYTHON_VERRUN $CONDA_DIR/bin/conda init# Set the environment variable for Anaconda installationENV PATH $CONDA_DIR/bin:$PATH# Reload the .bashrc file# To load base condaRUN /bin/bash -c "source ~/.bashrc || true"# activate condaRUN echo "conda activate $PROJECT_NAME" >> ~/.bashrcRUN /bin/bash -c "source ~/.bashrc || true"RUN /bin/bash -c "source activate $PROJECT_NAME && \ pip install Flask-Cors jupyter wandb opencv-python chardet pandas matplotlib scikit-learn flask bcrypt pymysql seaborn"# Install PyTorchRUN /bin/bash -c "source activate $PROJECT_NAME && \ pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118"# Copy your application code into the containerCOPY ./requirements.txt /home/$USER_NAME/workspace# Install any needed dependencies specified in requirements.txtRUN /bin/bash -c "source activate $PROJECT_NAME && \ pip install --no-cache-dir -r requirements.txt"# After pytorchRUN /bin/bash -c "source activate $PROJECT_NAME && \ pip install torcheval efficientnet_pytorch paramiko"# Copy the files and set permissions/ownership in a single stepCOPY --chown=$USER_NAME:$USER_NAME ./moving_ai /home/$USER_NAME/workspace/moving_ai# Install dependencies and run unit testsRUN test -d /home/$USER_NAME/workspace/moving_ai/DINO/models/dino/ops && \ rm -rf /home/$USER_NAME/workspace/moving_ai/DINO/models/dino/ops || trueRUN cd /home/$USER_NAME/workspace/moving_ai && \ cp -r dino_ops/ops DINO/models/dino/opsRUN cd /usr/local/cuda# Verify environment variablesRUN echo "CUDA_HOME: $CUDA_HOME"RUN echo "PROJECT_NAME: $PROJECT_NAME"RUN echo "USER_NAME: $USER_NAME"# To load environment variablesRUN /bin/bash -c "source ~/.bashrc || true"# RunRUN $CONDA_DIR/bin/activate mov && \ cd /home/$USER_NAME/workspace/moving_ai && \ cd DINO/models/dino/ops && \ python setup.py build install
I received the error:
=> ERROR [43/43] RUN /home/user/anaconda3/bin/activate mov && cd /home/user/workspace/moving_ai && cd DINO/models/dino/ops && python setup.py build install 1.6s------> [43/43] RUN /home/user/anaconda3/bin/activate mov && cd /home/user/workspace/moving_ai && cd DINO/models/dino/ops && python setup.py build install:#0 1.404 No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'#0 1.404 Traceback (most recent call last):#0 1.404 File "/home/user/workspace/moving_ai/DINO/models/dino/ops/setup.py", line 72, in <module>#0 1.404 ext_modules=get_extensions(),#0 1.404 File "/home/user/workspace/moving_ai/DINO/models/dino/ops/setup.py", line 38, in get_extensions#0 1.404 raise NotImplementedError('torch.cuda.is_available() is False')#0 1.404 NotImplementedError: torch.cuda.is_available() is False------Dockerfile:138-------------------- 137 | # # Run 138 | >>> RUN $CONDA_DIR/bin/activate mov && \ 139 | >>> cd /home/$USER_NAME/workspace/moving_ai && \ 140 | >>> cd DINO/models/dino/ops && \ 141 | >>> python setup.py build install 142 | --------------------ERROR: failed to solve: process "/bin/sh -c $CONDA_DIR/bin/activate mov && cd /home/$USER_NAME/workspace/moving_ai && cd DINO/models/dino/ops && python setup.py build install" did not complete successfully: exit code: 1
But if I remove the last part "python setup.py build install" and make the docker, it works well. And then execute "python setup.py build install" in the running container, it works well either.
Please help me to fix this problem.