Skip to content

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

Closed
Cyb3rDudu wants to merge 2 commits into
Mcrich23:mainfrom
Cyb3rDudu:fix/relative-bind-mounts
Closed

fix(up): normalize relative bind mount paths to absolute#84
Cyb3rDudu wants to merge 2 commits into
Mcrich23: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
@Cyb3rDudu
Copy link
Copy Markdown
Contributor Author

Last one — just a nudge on the bind mount normalization. There's some adjacent work in #94 (file mounts) but this PR handles the relative path case separately. Let me know if you'd prefer these combined.

@Mcrich23
Copy link
Copy Markdown
Owner

@Cyb3rDudu thank you for all of the PRs. I just merged #94 and it seems to have created a merge conflict. If you fix that, I would be happy to merge it in! Hoping to release 0.12.0 with all of these changes tomorrow.

@Cyb3rDudu
Copy link
Copy Markdown
Contributor Author

Superseded by #94 which resolves relative bind mount paths via resolvedPath(for:relativeTo:) in the refactored composeVolumeToRunArgs(). The core normalization is the same; #94 also added file mount forwarding on top.

@Cyb3rDudu Cyb3rDudu closed this May 29, 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

2 participants