conda-forge / miniforge

A conda-forge distribution.
https://conda-forge.org/miniforge
Other
6.25k stars 323 forks source link

conda command not found after installing miniforge (non-interactive method) #476

Closed JavierYepez closed 1 year ago

JavierYepez commented 1 year ago

Solution to issue cannot be found in the documentation.

Issue

I'm trying to install mamba in a docker image following the steps on the README.md:

FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04

# set bash as current shell
RUN chsh -s /bin/bash
SHELL ["/bin/bash", "-c"]

...

RUN wget -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
RUN bash Miniforge3.sh -b -p "${HOME}/conda"
RUN source "${HOME}/conda/etc/profile.d/conda.sh"
RUN conda activate

But conda is not being found:

 => CACHED [ 5/31] RUN bash Miniforge3.sh -b -p "${HOME}/conda"                                                                                                                                      0.0s
 => CACHED [ 6/31] RUN source "${HOME}/conda/etc/profile.d/conda.sh"                                                                                                                                 0.0s
 => ERROR [ 7/31] RUN conda activate                                                                                                                                                                 0.1s
------
 > [ 7/31] RUN conda activate:
0.137 /bin/bash: conda: command not found

I also tried some ideas from #359

Installed packages

Can’t install conda

Environment info

Can't install conda
jaimergp commented 1 year ago

source won't survive different RUN invocations (it only lasts a single bash session), but you can rewrite like this:

RUN wget -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
RUN bash Miniforge3.sh -b -p "${HOME}/conda"
RUN source "${HOME}/conda/etc/profile.d/conda.sh" \
    && conda activate \
    && conda install ....

Just remember to &&-chain all your conda commands together in the same RUN after source+activate.

JavierYepez commented 1 year ago

Oh, I didn’t know about it. Thank you @jaimergp

Is there a way to maintain an environment active?

jaimergp commented 1 year ago

You would need to add the source + activate code in .bashrc or similar, and then ensure this is loaded for each bash run (even if not a login or interactive session). Usually done via conda init but you'll need to do some debugging. Search github for Dockerfiles that mention conda, the code search is quire good these days.

JavierYepez commented 1 year ago

Ok, thank you