continuumio/miniconda3 环境的更清洁的 Dockerfile?
Cleaner Dockerfile for continuumio/miniconda3 environment?
我有一个 Python3.9 / Quart / Hypercorn 微服务,它 运行 在配置有 environment.yml 文件的 conda 环境中。基本图像是 continuumio/miniconda3.
由于 conda init 问题等,花了很多技巧才启动这个
有没有一种更简洁的方法可以在 Docker 中安装和激活 conda 环境,而不必求助于 conda 运行 命令并覆盖默认的 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
描述了另一种方法 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
我有一个 Python3.9 / Quart / Hypercorn 微服务,它 运行 在配置有 environment.yml 文件的 conda 环境中。基本图像是 continuumio/miniconda3.
由于 conda init 问题等,花了很多技巧才启动这个
有没有一种更简洁的方法可以在 Docker 中安装和激活 conda 环境,而不必求助于 conda 运行 命令并覆盖默认的 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
描述了另一种方法 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