Reuse -v/--volume to mount named/host volumes into -r/--run

Volume names now reject '/', which lets a -v spec used with -r be told
apart as either an existing named volume or a host directory path. -v
becomes repeatable with -r, each mounting a volume at an absolute
container path; if the host directory is empty and the image already
has content there, it's copied in first (preserving numeric
ownership/permissions/links/xattrs-ACLs, degrading gracefully with a
warning if the host filesystem doesn't support xattrs). The
existence-check and copy run through the same nsenter-wrapped
namespace bwrap itself needs, since a rootless containers-storage
mount's content isn't otherwise visible to this process at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
This commit is contained in:
2026-08-21 17:08:16 +00:00
parent d69b408d14
commit 545762d6de
8 changed files with 397 additions and 57 deletions
+13 -9
View File
@@ -18,10 +18,10 @@ running kernel actually supports, instead of requiring the full set.
Early-stage. Mounting, running, and dropping privileges to a specific user/group all
work. Named volumes (`-v/--volume`) can be created and are persisted in the config
file, but aren't consumed by `-r/--run` yet. Image-declared networking
(`ExposedPorts`/`Env` from the image config, and the image's own separately-declared
`Volumes`) are parsed but not yet applied, and there's no background/daemonized run
mode yet.
file, and can be mounted into `-r/--run` (repeatably), along with ad hoc host
directories. Image-declared networking (`ExposedPorts`/`Env` from the image config,
and the image's own separately-declared `Volumes`) are parsed but not yet applied,
and there's no background/daemonized run mode yet.
## Requirements
@@ -53,7 +53,7 @@ that `-r --user`/`--group` needs at runtime (see "How it works").
```
slocker-lite -m|--mount <image.tar>
slocker-lite -r|--run <image.tar> [-- <command> [args...]]
slocker-lite -r|--run <image.tar> [-v <name-or-dir> <container-path>]... [-- <command> [args...]]
slocker-lite -u|--umount <layer-id>
slocker-lite -c|--cleanup <layer-id>
slocker-lite -l|--list-images <directory>
@@ -78,7 +78,7 @@ slocker-lite -V|--version
| `--group <group>` | With `--user`, use this group (name or numeric gid) instead of the user's primary group. |
| `-l, --list-images <dir>` | List OCI Image Layout tars (`*.tar`, `*.tar.*`) found directly in `<dir>`, with their `name:tag`. |
| `-i, --inspect <image.tar>` | Print an image's declared user, exposed ports, env, volumes, and default command, without mounting or running it. |
| `-v, --volume <name> <dir>` | Create a named volume mapped to a host directory (created if missing), recorded in the config file's `volumes` section. Fails if the name or directory is already used by an existing volume. |
| `-v, --volume <name> <dir>` | Create a named volume mapped to a host directory (created if missing), recorded in the config file's `volumes` section. Fails if the name or directory is already used by an existing volume. Volume names can't contain `/`. With `--run`, instead mounts a volume into the sandbox (repeatable): `<name>` is an existing named volume, or, if it contains `/`, a host directory path (created if missing); `<dir>` is the absolute path inside the container to mount it at. If the host directory is empty and the image already has content there, that content is copied in first, preserving numeric ownership/permissions/links and, where the host filesystem supports them, extended attributes/ACLs (skipped with a warning otherwise). |
| `--list-volumes` | List all named volumes (see `-v/--volume`) with their host directory. |
| `--delete-volume <name>` | Remove a named volume from the config. The host directory is left untouched. |
| `--delete-volume-full <name>` | Like `--delete-volume`, but also recursively deletes the volume's host directory. |
@@ -111,6 +111,9 @@ sudo ./buildDir/slocker-lite -r myimage.tar --user git
# Create a named volume backed by a host directory
./buildDir/slocker-lite -v mydata ~/slocker-volumes/mydata
# Run, mounting that named volume plus an ad hoc host directory
./buildDir/slocker-lite -r myimage.tar -v mydata /data -v ~/scratch /scratch
# List all named volumes
./buildDir/slocker-lite --list-volumes
@@ -138,9 +141,10 @@ volumes:
`global.log-level` is the only standing preference supported today (one-shot
commands like `--mount`/`--run`/`--user` don't belong in a config file). An explicit
`--log-level` on the command line always overrides the config file. The `volumes`
section is managed by `-v/--volume` (see above) rather than hand-edited — it's not
consumed by `-r/--run` yet. A missing config file is fine either way (nothing is
overridden, and one gets created the first time `-v/--volume` is used).
section is managed by `-v/--volume` (see above) rather than hand-edited — it's what
`-r/--run`'s own `-v` usage looks named volumes up in. A missing config file is fine
either way (nothing is overridden, and one gets created the first time
`-v/--volume` is used).
## How it works