【问题标题】:Cleaner Dockerfile for continuumio/miniconda3 environment?用于 continuumio/miniconda3 环境的更清洁的 Dockerfile?
【发布时间】:2021-11-22 07:42:58
【问题描述】:

我有一个 Python3.9 / Quart / Hypercorn 微服务,它在配置了 environment.yml 文件的 conda 环境中运行。基础镜像是 continuumio/miniconda3。

由于 conda init 问题等原因,需要进行大量黑客攻击才能启动。

有没有一种更简洁的方法可以在 Docker 中安装和激活 conda 环境,而无需求助于 conda run 命令并覆盖默认的 SHELL 命令?

FROM continuumio/miniconda3

COPY . /api/

WORKDIR /api/src

# See this tutorial for details https://pythonspeed.com/articles/activate-conda-dockerfile/
RUN conda env create -f /api/conda_environment_production.yml
SHELL ["conda", "run", "-n", "ms-amazing-environment", "/bin/bash", "-c"]
ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "ms-amazing-environment", "hypercorn", "--bind", "0.0.0.0:5000", "QuartAPI:app"]

EXPOSE 5000

【问题讨论】:

    标签: python docker conda quart hypercorn


    【解决方案1】:

    here 描述了另一种方法。

    基本上你可以在 bash 脚本中激活 conda 环境并在那里运行你的命令。

    entrypoint.sh:

    #!/bin/bash --login
    # The --login ensures the bash configuration is loaded,
    
    # Temporarily disable strict mode and activate conda:
    set +euo pipefail
    conda activate ms-amazing-environment
    # enable strict mode:
    set -euo pipefail
    
    # exec the final command:
    exec hypercorn --bind 0.0.0.0:5000 QuartAPI:app
    

    Dockerfile:

    FROM continuumio/miniconda3
    
    COPY . /api/
    
    WORKDIR /api/src
    
    # See this tutorial for details https://pythonspeed.com/articles/activate-conda-dockerfile/
    RUN conda env create -f /api/conda_environment_production.yml
    
    # The code to run when container is started:
    COPY entrypoint.sh ./
    ENTRYPOINT ["./entrypoint.sh"]
    
    EXPOSE 5000
    

    【讨论】:

    • 效果很好。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2022-12-18
    • 2017-11-12
    • 2022-10-23
    相关资源
    最近更新 更多