Ale*_*lex 5 python bash docker conda
我创建了一个带有 bash 脚本的图像,该脚本ENTRYPOINT本身会从conda环境中启动一个可执行文件。我直接从单层(目前)构建它,我意识到这不是最佳实践,但让我们暂时忽略它......
文件
FROM alexholehouse/seq_demo:demo_early
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/seq_demo/launcher/launcher.sh"]
Run Code Online (Sandbox Code Playgroud)
哪里launcher.sh是
#!/bin/bash
# source bashrc which includes conda init section (and works fine in an interactive terminal)
source /root/.bashrc
# activate the conda environment
conda activate custom_conda
if [ -d /mount ]
then
cd /mount
# run the executable from the conda environment
demo_seq -k KEYFILE.kf
else
echo "No storage mounted..."
fi
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当我使用上述 Dockerfile 构建映像时,.bashrc由于.bashrc.
[ -z "$PS1" ] && return
... <bashrc stuff>
__conda_setup="$('/root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then
. "/root/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/root/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
Run Code Online (Sandbox Code Playgroud)
所以运行图像使用
docker run -it -v $(pwd):/mount b29c47a060
Run Code Online (Sandbox Code Playgroud)
手段.bashrc没有来源并且launcher.sh失败,因为无法找到 conda。
另一方面,如果我编辑.bashrc所有 conda 内容都在该[ -z "$PS1" ] && return行上方,那么 (a) conda 被获取,(b) .bashrc 的其余部分也被读取。
现在,编辑.bashrc解决了我的问题,但这不是正确的方法!那么,设置图像/Dockerfile 的正确方法是什么:
(a) 在运行容器时运行特定的 bash 脚本,以及 (b) 该 bash 脚本提供 .bashrc
我觉得我只是在这里错过了一些非常明显的东西......
| 归档时间: |
|
| 查看次数: |
351 次 |
| 最近记录: |