在docker file中,解决无法启动conda环境的问题

其实标题党,看了谷歌的内容也没有解决。

这个问题就是镜像里已经打包好了conda环境,打开交互式shell时执行conda activate 你的env运行某个脚本,再python执行等等。但想把这个docker打包到某些平台上时,conda命令找不到,从而也没法进行下一步。

解决方法:

直接找到conda下的python环境运行指定的脚本即可,如:

/root/miniconda3/envs/wis/bin/python generate_asr_ast.py 

如果发现这个conda环境缺失一些包,需要加装也不用担心。

可以在dockerfile中,执行

 RUN /root/miniconda3/envs/wis/bin/pip install opencc-python-reimplemented

这样打出来的镜像就有了包

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Docker配置/opt/conda,您可以按照以下步骤进行操作: 1. 在Dockerfile,添加以下命令来创建/opt/conda目录: ```Dockerfile RUN mkdir /opt/conda ``` 2. 下载并安装Miniconda或Anaconda。您可以使用以下命令之一: - Miniconda: ```Dockerfile RUN curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ chmod +x Miniconda3-latest-Linux-x86_64.sh && \ ./Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \ rm Miniconda3-latest-Linux-x86_64.sh ``` - Anaconda: ```Dockerfile RUN curl -O https://repo.anaconda.com/archive/Anaconda3-latest-Linux-x86_64.sh && \ chmod +x Anaconda3-latest-Linux-x86_64.sh && \ ./Anaconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \ rm Anaconda3-latest-Linux-x86_64.sh ``` 上述命令会下载并安装Miniconda或Anaconda到/opt/conda目录。 3. 添加/opt/conda/bin到环境变量。您可以在Dockerfile使用以下命令: ```Dockerfile ENV PATH /opt/conda/bin:$PATH ``` 这将确保您可以直接使用conda和其他Miniconda/Anaconda相关命令。 4. 运行容器时,确保将宿主机的目录挂载到/opt/conda目录,以便在容器内使用conda环境。可以使用以下命令: ```bash docker run -v /host/path:/opt/conda -it <image_name> /bin/bash ``` 其,/host/path是宿主机上的目录路径。 这样,您就可以在Docker容器配置/opt/conda目录,并使用conda进行环境管理和软件安装。注意,这些步骤假设您已经有一个基本的Dockerfile和一个可用的镜像来构建和运行容器

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值