Skip to content

Comments

Initial support for volume mounting in CLI#14228

Draft
AmelBawa-msft wants to merge 2 commits intofeature/wsl-for-appsfrom
user/amelbawa/volume
Draft

Initial support for volume mounting in CLI#14228
AmelBawa-msft wants to merge 2 commits intofeature/wsl-for-appsfrom
user/amelbawa/volume

Conversation

@AmelBawa-msft
Copy link

Summary of the Pull Request

🦞 Volume mounting parser

Parser support examples:

✅ Valid

C:\data:/data
C:\data:/data:ro
C:/data:/data
C:/data:/data:rw

❌ Invalid

:
::
::ro
C:\data:/data:z

🦐 Full example

# -v <host path>:<container path>[:mode]
wslc container run -v "C:/src/wsl/bin/x64/Debug/volume:/usr/share/nginx/html" -it --name demo2 nginx:alpine

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial CLI support for bind-mounting a host path into a container by parsing -v/--volume and wiring it into the container creation flow.

Changes:

  • Introduces a VolumeMount model with a parser for <host path>:<container path>[:mode].
  • Adds --volume/-v argument to wslc container run and wslc container create.
  • Plumbs the parsed volume into WSLAContainerLauncher::AddVolume(...) during container creation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/windows/wslc/ContainerService.cpp Applies parsed volume mount to the container launcher before creation.
src/windows/wslc/ContainerModel.h Adds Volume option field and declares VolumeMount parsing API.
src/windows/wslc/ContainerModel.cpp Implements parsing/splitting logic for Windows-drive-aware -v syntax.
src/windows/wslc/ContainerCommand.h Exposes --volume/-v in run and create commands.
src/windows/wslc/CMakeLists.txt Adds the new model implementation file to the build.

Comment on lines +66 to +67
THROW_HR_WITH_USER_ERROR(E_INVALIDARG, "Volume mount value must be in the format <host path>:<container path>[:mode]");
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THROW_HR_WITH_USER_ERROR formats the message with a wide format string (std::format(L"{}", Message)), so passing a narrow string literal here is likely not formattable and can break the build. Use a wide string literal (L"...") or a std::wstring/localized message instead.

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +72
auto parts = SplitVolumeValue(value);
if (parts.size() < 2 || parts.size() > 3)
{
THROW_HR_WITH_USER_ERROR(E_INVALIDARG, "Volume mount value must be in the format <host path>:<container path>[:mode]");
}

VolumeMount vm;
vm.m_hostPath = parts[0];
vm.m_containerPath = parts[1];
if (parts.size() == 3)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser currently allows empty host/container paths (e.g. ":" -> host="", container="" and "::ro" -> host="", container=""), but the PR description calls these invalid. Add validation that parts[0] and parts[1] are non-empty (and if a mode is present, it’s non-empty) before accepting the mount.

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +87
if (!options.Volume.empty())
{
auto volume = VolumeMount::Parse(options.Volume);
auto host = wsl::shared::string::MultiByteToWide(volume.HostPath());
auto container = volume.ContainerPath();
containerLauncher.AddVolume(host, container, volume.IsReadOnly());
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a single --volume value is supported end-to-end (options store one string and CreateInternal mounts at most one volume). Since the argument parser allows specifying -v/--volume multiple times, earlier values will be silently overwritten and only the last mount will be applied. Consider changing Volume to a list and calling AddVolume for each entry, or explicitly detect duplicates and throw a user error.

Suggested change
if (!options.Volume.empty())
{
auto volume = VolumeMount::Parse(options.Volume);
auto host = wsl::shared::string::MultiByteToWide(volume.HostPath());
auto container = volume.ContainerPath();
containerLauncher.AddVolume(host, container, volume.IsReadOnly());
if (!options.Volumes.empty())
{
for (const auto& volumeSpec : options.Volumes)
{
auto volume = VolumeMount::Parse(volumeSpec);
auto host = wsl::shared::string::MultiByteToWide(volume.HostPath());
auto container = volume.ContainerPath();
containerLauncher.AddVolume(host, container, volume.IsReadOnly());
}

Copilot uses AI. Check for mistakes.
"-t, --tty: Open a TTY with the container process",
"-i, --interactive: Keep stdin open",
"-d, --detach: Run container in background",
"-v, --volume: Bind mount a volume to the container",
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text for --volume doesn’t indicate that the flag takes a value or what format is expected. Align with the PR’s documented syntax (e.g. show <host>:<container>[:ro|rw]) to reduce user confusion.

Suggested change
"-v, --volume: Bind mount a volume to the container",
"-v, --volume <host>:<container>[:ro|rw]: Bind mount a volume into the container",

Copilot uses AI. Check for mistakes.
Comment on lines 78 to 82
"-t, --tty: Open a TTY with the container process",
"-i, --interactive: Keep stdin open",
"-v, --volume: Bind mount a volume to the container",
"--name <name>: Assign a name to the container that will be used as its container id",
};
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text for --volume doesn’t indicate that the flag takes a value or what format is expected. Align with the documented syntax (e.g. <host>:<container>[:ro|rw]) to reduce user confusion.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +78
{
THROW_HR_WITH_USER_ERROR(E_INVALIDARG, "Volume mount mode must be either 'ro' or 'rw'");
}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: THROW_HR_WITH_USER_ERROR expects a message formattable with a wide std::format(L"{}", ...), so this narrow string literal can fail to compile. Use a wide string literal or a localized std::wstring message.

Copilot uses AI. Check for mistakes.
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.

1 participant