Is there a `~/.bashrc` equivalent when `apptainer run`?
May 21, 7:21pm

No, apptainer run does not automatically source ~/.bashrc like an interactive login shell would.

Key Behavior:

  • apptainer run: Executes the %runscript in a non-interactive shell → .bashrc is not sourced.
  • apptainer shell: Starts an interactive shell → .bashrc is sourced (if using Bash and the file exists in the container or mounted home).

Equivalent Solutions:

  1. Explicitly source it in %runscript (for apptainer run):

    bash
    # In your Singularity/Apptainer definition file:
    %runscript
    source ~/.bashrc && exec "$@"
  2. Use BASH_ENV (for non-interactive Bash):

    bash
    %environment
    export BASH_ENV=/path/to/your/bashrc
  3. Switch to apptainer shell if you need an interactive environment with .bashrc loaded.

  4. Mount and source manually:

    bash
    apptainer run --bind ~/.bashrc:/root/.bashrc your_container.sif

    (Then ensure the runscript sources it.)

For most cases, option 1 or 2 is the cleanest equivalent.

May 21, 7:21pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more