[Python] Configure/Setting/Activate a Python Conda environment in Docker

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to set up a conda environment inside a docker container, but it always keep failing at the environment creation stage in the dockerfile with the error: conda activate" fails because shell is not initialized

    Below is my Dockerfile:

    FROM pytorch/pytorch:1.1.0-cuda10.0-cudnn7.5-runtime

    WORKDIR /app

    # SET BASH AS CURRENT SHELL
    RUN chsh -s /bin/bash
    SHELL ["/bin/bash", "-c"]

    # INSTALL ANACONDA
    RUN apt-get update -y

    RUN apt-get install -y wget && \
    apt-get clean


    RUN rm -rf /opt/conda && \
    wget --quiet https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh -O ~/anaconda.sh && \
    /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    rm ~/anaconda.sh && \
    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    find /opt/conda/ -follow -type f -name '*.a' -delete && \
    find /opt/conda/ -follow -type f -name '*.js.map' -delete && \
    /opt/conda/bin/conda clean -afy

    COPY ./requirements.yml /tmp/requirements.yml


    RUN conda update conda \
    && conda env create -f /tmp/requirements3.yml

    RUN echo "conda activate nib_docker" >> ~/.bashrc
    ENV PATH /opt/conda/envs/nib_docker/bin:$PATH
    ENV CONDA_DEFAULT_ENV $nib_docker

    COPY . .
    CMD [ "python", "-u", "train.py" ]

    Continue reading...

Compartilhe esta Página