Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems running conda update in a dockerfile

I am trying to create a docker container with some conda environments. When I run the container in interactive mode running

conda update --all
conda env create -f env.yml

runs with no issues. However whenever I try to execute these commands with a Docker file I recieve

/bin/sh: 1: conda: command not foud

Docker file is shown below:

FROM ubuntu:latest
RUN apt-get update && \
    apt-get install unzip && \
    mkdir /install && \
    apt-get install nano
COPY Anaconda3-2018.12-Linux-x86_64.sh env.yml /install/
WORKDIR /install
RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
    echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
    /bin/bash -c "source ~/.bashrc"
RUN conda update --all
RUN conda env create -f env.yml

So it appears that sh is being used instead of bash so I edited the Dockerfile to the following:

FROM ubuntu:latest
RUN apt-get update && \
    apt-get install unzip && \
    mkdir /install && \
    apt-get install nano
COPY Anaconda3-2018.12-Linux-x86_64.sh env.yml /install/
WORKDIR /install
RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
    echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
    /bin/bash -c "source ~/.bashrc"
RUN /bin/bash -c "conda update --all"

with the following error

/bin/bash: conda: command not found
like image 298
magladde Avatar asked Dec 17 '22 16:12

magladde


1 Answers

You have to add anaconda to the PATH during build time with the ENV variable before executing anaconda inside the Dockerfile.

RUN bash Anaconda3-2018.12-Linux-x86_64.sh -b && \
    echo "export PATH="/root/anaconda3/bin:$PATH"" >> ~/.bashrc && \
    /bin/bash -c "source ~/.bashrc"
ENV PATH /root/anaconda3/bin:$PATH
RUN conda update --all

Updating PATH in .bashrc will make it possible to call conda inside the container when run with docker run, but not in other RUN statements in the docker file.

like image 147
cel Avatar answered Jan 16 '23 06:01

cel