我正在尝试构建一个基于 micromamba 的容器,它会自动激活正确的环境来运行应用程序(此处
jupyter-lab
)。
Bootstrap: docker
From: mambaorg/micromamba:1.5.8
%files
environment.yaml /environment.yaml
%post
micromamba create -n __apptainer__ && \
micromamba install -n __apptainer__ --file environment.yaml && \
micromamba clean --all --yes
# Activate the environment and set it as default when starting the container
echo "source /opt/conda/bin/activate __apptainer__" >> $SINGULARITY_ENVIRONMENT
micromamba shell init --shell bash --root-prefix=~/micromamba
# Update PATH to include micromamba binaries and other environment variables
echo 'export PATH="/opt/conda/envs/__apptainer__/bin:$PATH"' >> $SINGULARITY_ENVIRONMENT
# Add micromamba shell hook and activation to Singularity environment script
echo '/usr/bin/micromamba activate __apptainer__' >> $SINGULARITY_ENVIRONMENT
name: __apptainer__
channels:
- conda-forge
dependencies:
- jupyterlab
用
apptainer build jupyter-lab-micromamba.sif Apptainer.def
构建容器后,我得到这个:
apptainer exec jupyter-lab-micromamba.sif which jupyter-lab
'micromamba' is running as a subprocess and can't modify the parent shell.
Thus you must initialize your shell before using activate and deactivate.
To initialize the current shell, run:
$ eval "$(micromamba shell hook --shell )"
and then activate or deactivate with:
$ micromamba activate
To automatically initialize all future () shells, run:
$ micromamba shell init --shell --root-prefix=~/micromamba
If your shell was already initialized, reinitialize your shell with:
$ micromamba shell reinit --shell
Otherwise, this may be an issue. In the meantime you can run commands. See:
$ micromamba run --help
Supported shells are {bash, zsh, csh, xonsh, cmd.exe, powershell, fish}.
critical libmamba Shell not initialized
/opt/conda/envs/__apptainer__/bin/jupyter-lab
它有效,但我想摆脱这个警告。
我尝试在
%post
: eval "$(micromamba shell hook --shell bash)"
期间运行它,但这也会产生问题。必须如何完成此操作,才能自动激活正确的环境?
请参阅 有关使用
mambaorg/micromamba
与 apptainer 的文档。与您的案例相关的特定部分是:
不执行入口点脚本,因此不会自动激活apptainer exec
环境。通过将base
添加到要在容器内执行的命令之前,您可以激活/usr/local/bin/_entrypoint.sh
环境。例如:base
apptainer exec /usr/local/bin/_entrypoint.sh micromamba info
我个人对 apptainer 并不熟悉,但如果这没有明确说明如何完成您想要做的事情,请随时在
mambaorg/micromamba
中提出问题,我们将尽力提供进一步帮助。