我有一个Python3.9 / Quart / Hypercorn微服务,它在配置了environment.yml文件的conda环境中运行。基本映像是continuumio/miniconda3。
由于conda初始化问题等原因,它花了很多时间才能启动。
有没有一种更干净的方法可以在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发布于 2021-11-22 08:23:42
描述了一种替代方法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:appDockerfile
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 5000https://stackoverflow.com/questions/70062383
复制相似问题