Activate and switch Anaconda environment in Dockerfile during build

后端 未结 3 1568
走了就别回头了
走了就别回头了 2020-12-09 10:47

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:

3条回答
  •  悲&欢浪女
    2020-12-09 11:04

    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:

    • List of Miniconda Docker tags
    • List of conda updates by channel: defaults, conda-forge

提交回复
热议问题