How to avoid the following to be able to list my host home folder files?

```bash
cd ~/apptainer/
apptainer shell --writable --fakeroot debian-sandbox/
```
```
WARNING: Error changing the container working directory. Using '/root' instead: chdir /scratch/loison_benjamin/apptainer: no such file or directory
Apptainer> ls
```
2/2
May 20, 9:10am

The warning you're seeing:

text
WARNING: Error changing the container working directory. Using '/root' instead: chdir /scratch/loison_benjamin/apptainer: no such file or directory

means that Apptainer cannot find the directory /scratch/loison_benjamin/apptainer inside the container when it tries to set your working directory. By default, Apptainer tries to mirror your current host directory inside the container, but if that path doesn't exist in the container, it falls back to /root.


Why This Happens

  • Apptainer containers are isolated environments. The host's /scratch/loison_benjamin/apptainer is not automatically available inside the container unless you explicitly bind it.
  • The --writable and --fakeroot flags do not affect directory mounting.

How to List Your Host Home Folder Files

1. Bind Your Host Home Directory

Use the --bind (or -B) option to mount your host home directory (or any directory) into the container. For example:

bash
apptainer shell --writable --fakeroot --bind ~/:/host_home debian-sandbox/
  • This binds your host home directory (~) to /host_home inside the container.
  • Inside the container, you can then cd /host_home and ls to see your host files.

2. Use /host for Automatic Home Binding

Apptainer automatically binds your host home directory to /host inside the container if you use the --contain or --home options, but the simplest way is to explicitly bind it as above.

3. List Files Directly

Once inside the container, you can list the bound directory:

bash
Apptainer> ls /host_home

Summary of Command

bash
cd ~/apptainer/
apptainer shell --writable --fakeroot --bind ~/:/host_home debian-sandbox/
Apptainer> ls /host_home

May 20, 9:10am

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

Le Chat can make mistakes. Check answers. Learn more