The behavior you're observing with apptainer run and your custom PS1 in ~/.bashrc is likely due to how Apptainer (formerly Singularity) handles shell initialization and the type of shell it invokes by default.
Here’s why this happens and how to fix it:
PS1 is Not AppliedNon-Interactive Shell by Default
When you run apptainer run my_debian.sif, Apptainer typically starts a non-interactive, non-login shell inside the container. In such shells, ~/.bashrc is not automatically sourced. However, some parts of your ~/.bashrc (e.g., aliases, functions, or environment variables) may still be applied if they are set in a way that Bash reads them even in non-interactive mode (e.g., via BASH_ENV or explicitly sourced).
PS1 is for Interactive Shells
The PS1 variable (your shell prompt) is only used by interactive shells. Since Apptainer’s default shell is non-interactive, PS1 is ignored.
Login vs. Non-Login Shells
apptainer shell my_debian.sif, it starts an interactive shell, and ~/.bashrc (and thus PS1) will be applied.apptainer run does not start an interactive shell by default, so PS1 is not loaded.If you want your custom PS1 to appear, use apptainer shell instead of apptainer run:
bashapptainer shell my_debian.sif
This will give you an interactive shell inside the container, and ~/.bashrc (including PS1) will be sourced.
~/.bashrc in apptainer runIf you must use apptainer run, you can force Bash to source ~/.bashrc by passing a command that starts an interactive shell:
bashapptainer run --shell /bin/bash my_debian.sif
Or, explicitly source it in your command:
bashapptainer exec my_debian.sif bash -c "source ~/.bashrc; your_command"
PS1 in a File Sourced by Non-Interactive ShellsIf you want PS1 to work even in non-interactive shells (uncommon, but possible), you can set it in a file that Bash reads for non-interactive shells, such as:
BASH_ENV environment variable (point it to a file containing PS1).--nv flag in Apptainer to pass your host’s environment.Example:
bashexport BASH_ENV=~/.bashrc apptainer run my_debian.sif
But this is not recommended, as PS1 is meant for interactive use.
apptainer runapptainer shellapptainer exec bashKey Takeaway:
PS1 is for interactive shells. Use apptainer shell or explicitly start an interactive shell if you want your custom prompt. For apptainer run, the shell is non-interactive by design, so PS1 is ignored.
Vibe can make mistakes. Check answers. Learn more