anaconda / docker-images

Repository of Docker images created by Anaconda
https://hub.docker.com/u/continuumio/
829 stars 282 forks source link

conda activate <SMTH> #81

Open Cinerar opened 6 years ago

Cinerar commented 6 years ago

I do: docker run -i -t continuumio/anaconda3 /bin/bash Then i try to activate any env (for ex base) with conda activate base i recieve

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc

or, for all users, enable conda with

    $ sudo ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bashrc

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file.  You should manually remove the line that looks like

    export PATH="/opt/conda/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^

I believe this is related with the change in recomended way to enable conda in shell https://github.com/conda/conda/releases/tag/4.4.0

more specifically this is the line that creates this problem https://github.com/ContinuumIO/docker-images/blob/13044336262c9401e35cd490c5545656d3241b2c/anaconda3/Dockerfile#L11

unfortunatelly i can't figure out how to fix it.

kalefranz commented 6 years ago

Yeah probably a problem. To fix this particular issue, from e.g. https://github.com/ContinuumIO/docker-images/blob/master/anaconda3/Dockerfile#L11

we should change

RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
    wget --quiet https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh -O ~/anaconda.sh && \
    /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    rm ~/anaconda.sh

to

RUN wget --quiet https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh -O ~/anaconda.sh && \
    /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    rm ~/anaconda.sh && \
    ln -s /opt/anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
p-himik commented 6 years ago

For Miniconda3 4.4.10, I still receive the same error despite the changes.

Update: interestingly, it was fixed by removing RUN conda activate base from my Dockerfile.

altaha commented 6 years ago

Adding echo "conda activate base" >> ~/.bashrc can be problematic if PATH is configured to point to particular conda env. Now anytime you try to get a bash shell, it will switch to base env which perhaps someone does not expect. Is this a desirable change? Could this issue have been fixed without forcing base env? I imagine this might trick others as well

saulshanabrook commented 6 years ago

I ended up using the frolvlad/alpine-miniconda3 image and using the source activate <name> command in it. This is how I used it in CircleCI:

version: 2
jobs:
  conda:
    docker:
      - image: frolvlad/alpine-miniconda3
    steps:
      # gcc for numba install
      - run: apk add --no-cache build-base ca-certificates git openssh
      - checkout
      - restore_cache:
          keys:
            - conda-pkgs
      - run: conda env create
      - save_cache:
          key: conda-pkgs
          paths:
            - /opt/conda/pkgs
      - run: source activate numba-xnd && cd numba && python setup.py develop
      - run: source activate numba-xnd && python -m unittest
workflows:
  version: 2
  test:
    jobs:
      - conda