【发布时间】:2022-01-12 23:15:06
【问题描述】:
我正在尝试使用 conda 环境构建 docker 映像并在启动容器时启动环境,但我不知道如何操作。我的 Dockerfile 目前是:
FROM nvidia/cuda:10.2-cudnn7-runtime-ubuntu18.04
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt update \
&& apt install -y htop python3-dev wget git imagemagick
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir root/.conda \
&& sh Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh \
&& conda create -y -n .venv python=3.7
RUN /bin/bash -c "source activate .venv \
&& pip install -r requirements.txt"
# More omitted installs
CMD ["/bin/bash", "source activate .venv"]
RUN /bin/bash -c "source activate .venv"
然后我构建并运行:
docker build -f Dockerfile -t adlr .
docker run -it adlr /bin/bash
-->conda 环境在启动容器时没有被激活,但我希望它是。
【问题讨论】:
-
在链接的问题中,我偏爱this answer,它使用入口点包装器运行
conda activate,然后运行图像的CMD,但那里列出了几种替代方案(包括一个您开始更新.bashrc,然后将默认SHELL设置为实际读取它)。
标签: bash docker anaconda dockerfile conda