Skip to content

fix(up): normalize relative bind mount paths to absolute#84

Open
Cyb3rDudu wants to merge 2 commits intoMcrich23:mainfrom
Cyb3rDudu:fix/relative-bind-mounts
Open

fix(up): normalize relative bind mount paths to absolute#84
Cyb3rDudu wants to merge 2 commits intoMcrich23:mainfrom
Cyb3rDudu:fix/relative-bind-mounts

Conversation

@Cyb3rDudu
Copy link
Copy Markdown
Contributor

Compose files using relative bind mounts fail to start:

services:
  app:
    image: node:latest
    volumes:
      - ./app:/app
app: Error: invalidArgument: "Invalid volume name './app': must match ^[A-Za-z0-9][A-Za-z0-9_.-]*$"

configVolume already computes an absolute fullHostPath for the directory-create path, but passes the original relative source to container run -v. The daemon then runs the value through its volume-name regex and rejects it.

Pulls the source-path resolution into a static helper resolveBindMountSource(_:cwd:) and wires configVolume through it. Already-absolute and ~-prefixed paths pass through unchanged; relative paths get joined to cwd and standardized via URL.standardizedFileURL, collapsing ./ and ../ segments. The runtime side of the fix is the same as #42; this PR adds the unit tests Morris asked for there.

Tests: 9 static cases for the helper covering ./foo, bare relative, ../foo, intermediate .., absolute pass-through, ~/foo literal preservation, .//foo double-slash, and the exact ./app case from the issue.

Fixes #4. Supersedes #42 (credit to @ttys3 for the original approach).

Cyb3rDudu added 2 commits May 4, 2026 15:26
Apple `container` rejects `./app:/app` style bind mounts because the
volume-name validation regex `^[A-Za-z0-9][A-Za-z0-9_.-]*$` doesn't
match strings starting with `./`, `../`, or containing `/`. The
existing code computed an absolute `fullHostPath` for FileManager but
still passed the original relative `source` to `container run -v`,
producing "Invalid volume name './app'" at startup.

Extract the source-path resolution into a static helper
`resolveBindMountSource(_:cwd:)` and wire `configVolume` through it.
Already-absolute and `~`-prefixed paths pass through unchanged;
relative paths get joined to `cwd` and standardized via
`URL.standardizedFileURL`, collapsing `./` and `../` segments.

Picks up the approach from Mcrich23#42; testable static helper makes the
behavior covered by unit tests rather than only verifiable via a
full `compose up`.

Fixes Mcrich23#4.
9 cases for resolveBindMountSource:
- `./foo` → `<cwd>/foo`
- bare relative `foo/bar` → `<cwd>/foo/bar`
- `../foo` → `<parent>/foo`
- intermediate `..` collapses (`foo/../bar` → `<cwd>/bar`)
- absolute `/abs/foo` passes through unchanged
- already-absolute path with `/./` is left alone (don't second-guess)
- `~/foo` left literal for apple/container to expand
- `.//foo` double-slash collapses
- the issue Mcrich23#4 `./app` case + post-conditions for the validation regex
Cyb3rDudu added a commit to Cyb3rDudu/Container-Compose that referenced this pull request May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Relative Bind Mounts

1 participant