I\'ve been trying for hours and can\'t figure out how to activate and switch anaconda environments in a Dockerfile during the build process
Here\'s the initial code:
Assuming you want to install the conda environment and run something in it, this approach uses ENV PATH to launch python indirectly in that conda environment. One can be left wondering if this approach really activates the environment, but so long as the subsequent commands work, and indeed they do, it may not matter.
FROM continuumio/miniconda3:latest
WORKDIR myappdir
COPY environment.yml .
RUN set -x && \
# apt-get update && apt-get -y install gcc && \
conda install -n base -c defaults conda=4.* && \
conda env create -n condaenv # Installs environment.yml && \
conda clean -a
COPY myapppkg myapppkg
ENV PATH /opt/conda/envs/condaenv/bin:$PATH
ENTRYPOINT ["python", "-m", "myapppkg"]
I advise against using conda run while it is experimental due to a history of severe bugs such as this one affecting it. Although this particular bug is now fixed, its continued "experimental" nature as shown by conda run -h means that it can again break upstream, limiting the trust that one can place in it.
For reference: