I am trying to build a micromamba based container, that automatically activates the correct environment.
Apptainer.def
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
# 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
environment.yaml
name: __apptainer__
channels:
- conda-forge
dependencies:
- jupyterlab
after building the container with apptainer build jupyter-lab-micromamba.sif Apptainer.def
, I get this:
apptainer shell jupyter-lab-micromamba.sif
Apptainer> micromamba env list
Name Active Path
────────────────────────────────────────────────────────
* /home/username/miniforge3
base /opt/conda
__apptainer__ /opt/conda/envs/__apptainer__
bash: __vte_prompt_command: command not found
Apptainer> micromamba activate __apptainer__
'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 bash shell, run:
$ eval "$(micromamba shell hook --shell bash)"
and then activate or deactivate with:
$ micromamba activate
To automatically initialize all future (bash) shells, run:
$ micromamba shell init --shell bash --root-prefix=~/micromamba
If your shell was already initialized, reinitialize your shell with:
$ micromamba shell reinit --shell bash
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
bash: __vte_prompt_command: command not found
Apptainer> eval "$(micromamba shell hook --shell bash)"
bash: __vte_prompt_command: command not found
Apptainer> micromamba activate __apptainer__
I tried to run this during %post
: eval "$(micromamba shell hook --shell bash)"
, but that also produces problems. How must this be done, so that the correct enviroment is automatically active?