0

I’m on a Mac and trying to build a new container (new to Docker), I can get Anaconda installed fine and updating Anaconda from within the container works, however when I try to run conda update conda from the Dockerfile I get the below error:

What am I doing wrong?

Thanks!

The command '/bin/sh -c conda update conda' returned a non-zero code: 127




FROM ubuntu:18.04
RUN apt-get update && \
    apt-get -y install curl && \
    apt-get -y install python3 && \
    apt-get -y install python3-pip && \
    python3 -m pip install --upgrade pip && \
    apt-get -y install wget && \
    apt-get -y install vim && \
    pip3 install tensorflow && \
    pip3 install keras


RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-5.3.0-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 && \
    echo "conda activate base" >> ~/.bashrc

RUN conda update conda
RUN conda install opencv
RUN conda install matplotlib
RUN conda install pandas
RUN conda install seaborn
Nizmon
  • 43
  • 8
  • 1
    (1) Just because you put something in `/etc/profile.d` doesn't mean future `RUN`s are going to implicitly have those variables set. `.bashrc` is used for *interactive* shells only; `sh -c ...whatever...` is a noninteractive shell invocation, so it doesn't run `.bashrc`. – Charles Duffy Mar 10 '19 at 17:34
  • (2) I'm really hoping this is Docker doing an abysmally bad job of formatting its error messages, as opposed to generating a command line that makes no sense on its face: `/bin/sh -c conda update conda`, when run with that exact quoting, completely ignores the `update conda` arguments and just runs `conda` with no additional arguments. It would need to be `/bin/sh -c 'conda update conda'` to actually work. – Charles Duffy Mar 10 '19 at 17:34
  • 1
    That said, changing your `RUN`s to be of the form `RUN . ~/.bashrc && conda update conda` may be all you need if it's just the first problem. – Charles Duffy Mar 10 '19 at 17:36
  • ...so, the reason you can run `conda update conda` from an *interactive* shell in the container is that, being an interactive shell, it honors `.bashrc` implicitly; whereas the ones started by `RUN` don't unless told to do so explicitly. – Charles Duffy Mar 10 '19 at 17:38
  • @CharlesDuffy - thanks for your quick response. Yeah I figured it was something to do with RUN not using the shell. After trying RUN . ~/.bashrc && conda update conda it shows me the following messages which I'm not sure of and am looking up now /bin/sh: 13: /root/.bashrc: shopt: not found /bin/sh: 21: /root/.bashrc: shopt: not found – Nizmon Mar 10 '19 at 17:47
  • That error means your script requires bash but is being run with /bin/sh instead. – Charles Duffy Mar 10 '19 at 17:51
  • 1
    `RUN ["/bin/bash", "-c", "source ~/.bashrc && conda update conda"]` is one means to avoid the use of `/bin/sh` at all. – Charles Duffy Mar 10 '19 at 17:53
  • Possible duplicate of [How to use bash profile in dockerfile](https://stackoverflow.com/questions/52493995/how-to-use-bash-profile-in-dockerfile) – Charles Duffy Mar 10 '19 at 17:57
  • @CharlesDuffy - thank you, very much appreciated! – Nizmon Mar 10 '19 at 18:02

0 Answers0