【待试验】使用dockerfile方式安装conda

#!/bin/bash

FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04

...

RUN conda create -n torch -y python=3.8
# 用于激活环境,conda activate命令无效
SHELL ["conda", "run", "-n", "ffmpeg_env", "/bin/bash", "-c"]
# 成功激活
RUN  conda activate torch
RUN pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

...
参考文章

Dockerfile中创建并激活conda环境_harry_tea的博客-CSDN博客

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dockerfile 中执行 `source` 命令使用 conda 环境,可以按照以下步骤进行: 1. 在 Dockerfile安装 conda,并创建一个新的 conda 环境: ``` RUN curl -sSLO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ && bash Miniconda3-latest-Linux-x86_64.sh -b \ && rm Miniconda3-latest-Linux-x86_64.sh \ && echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc \ && echo "conda activate myenv" >> ~/.bashrc \ && /opt/conda/bin/conda create -y --name myenv python=3.7 \ && /opt/conda/bin/conda clean -ya ``` 这里创建了一个名为 `myenv` 的 conda 环境,并将其添加到了 `.bashrc` 文件中,以便后续可以使用该环境。 2. 在需要使用 conda 环境的命令前,使用 `bash -c` 执行 `source activate` 命令激活 conda 环境: ``` RUN bash -c "source activate myenv && pip install -r requirements.txt" ``` 这里使用 `source activate myenv` 命令激活了 `myenv` 环境,然后执行了 `pip install` 命令。 注意,如果你使用的是 conda 4.4 以上版本,可以使用 `conda activate` 命令代替 `source activate` 命令。 完整的 Dockerfile 可以参考以下示例: ``` FROM ubuntu:18.04 # Install conda RUN apt-get update \ && apt-get install -y curl bzip2 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* RUN curl -sSLO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ && bash Miniconda3-latest-Linux-x86_64.sh -b \ && rm Miniconda3-latest-Linux-x86_64.sh \ && echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc \ && echo "conda activate myenv" >> ~/.bashrc \ && /opt/conda/bin/conda create -y --name myenv python=3.7 \ && /opt/conda/bin/conda clean -ya # Copy files COPY . /app WORKDIR /app # Install dependencies RUN bash -c "source activate myenv && pip install -r requirements.txt" # Run command CMD ["bash"] ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值