← 返回命令列表

Linux command

apptainer-exec 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Execute a command

apptainer exec [container.sif] [command]

Run with bound directory

apptainer exec --bind [/host/path]:[/container/path] [container.sif] [command]

Execute with writable overlay

apptainer exec --overlay [overlay.img] [container.sif] [command]

Run with GPU support

apptainer exec --nv [container.sif] [command]

Execute from Docker Hub

apptainer exec docker://[image:tag] [command]

Run with isolated network

apptainer exec --net --network none [container.sif] [command]

Execute with custom environment variable

apptainer exec --env [VAR=value] [container.sif] [command]

Run in a writable sandbox directory

apptainer exec --writable [sandbox/] [command]

说明

apptainer exec runs a specified command inside an Apptainer container. Unlike apptainer shell which provides an interactive session, exec runs a single command and returns its exit status, making it ideal for batch processing and scripts. The container can be specified as a local SIF file, a library URI (library://), a Docker URI (docker://), or an OCI archive. The command and any arguments are executed within the container environment with the current user's identity preserved. By default, Apptainer mounts the current directory, home directory, and standard system paths into the container. Additional paths can be bound using --bind. For HPC workloads, the --nv or --rocm flags enable GPU passthrough. The command inherits the host's environment by default. Use --cleanenv for reproducibility or --contain for isolation. Exit status reflects the executed command's return code.

参数

--bind, -B _src:dest[:opts]_
Bind mount a path from the host into the container.
--overlay _image_
Use an overlay filesystem for writable layer.
--nv
Enable NVIDIA GPU support inside the container.
--rocm
Enable AMD ROCm GPU support.
--contain, -c
Use minimal /dev and empty other directories.
--containall, -C
Full isolation: contain filesystems plus new PID and IPC namespaces and clean environment.
--cleanenv, -e
Clean environment before running container.
--env _VAR=value_
Set environment variable in container.
--env-file _file_
Load environment variables from file.
--home _path_
Set custom home directory.
--cwd _path_
Set initial working directory in container. (--pwd is a deprecated synonym.)
--net
Enable network namespace.
--network _type_
Specify network type (none, bridge, etc.).
--fakeroot
Run container with fake root privileges.
--writable-tmpfs
Add writable tmpfs overlay.
--no-mount _type_
Disable a specific mount point. Valid values: proc, sys, dev, devpts, home, tmp, hostfs, cwd.
--no-home
Do not mount the user's home directory into the container.
--writable, -w
Make the container filesystem read-write (requires a writable image or sandbox directory).
--scratch, -S _dir_
Include a scratch directory within the container that is linked to a temporary directory on the host.
--workdir, -W _path_
Working directory used for /tmp, /var/tmp, and $HOME overrides when using --contain or --scratch.
--ipc, -i
Run container in a new IPC namespace.
--pid, -p
Run container in a new PID namespace.
--userns, -u
Run container in a new user namespace.
--uts
Run container in a new UTS namespace.

FAQ

What is the apptainer-exec command used for?

apptainer exec runs a specified command inside an Apptainer container. Unlike apptainer shell which provides an interactive session, exec runs a single command and returns its exit status, making it ideal for batch processing and scripts. The container can be specified as a local SIF file, a library URI (library://), a Docker URI (docker://), or an OCI archive. The command and any arguments are executed within the container environment with the current user's identity preserved. By default, Apptainer mounts the current directory, home directory, and standard system paths into the container. Additional paths can be bound using --bind. For HPC workloads, the --nv or --rocm flags enable GPU passthrough. The command inherits the host's environment by default. Use --cleanenv for reproducibility or --contain for isolation. Exit status reflects the executed command's return code.

How do I run a basic apptainer-exec example?

Run `apptainer exec [container.sif] [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --bind, -B _src:dest[:opts]_ do in apptainer-exec?

Bind mount a path from the host into the container.