Skip to content

Add --network option to container create/run (excluding host mode)#40720

Open
AmelBawa-msft wants to merge 8 commits into
masterfrom
user/amelbawa/container-network
Open

Add --network option to container create/run (excluding host mode)#40720
AmelBawa-msft wants to merge 8 commits into
masterfrom
user/amelbawa/container-network

Conversation

@AmelBawa-msft
Copy link
Copy Markdown
Contributor

@AmelBawa-msft AmelBawa-msft commented Jun 5, 2026

Summary of the Pull Request

Adds --network support to container run and container create, letting users connect containers to one or more networks.
--network host is explicitly rejected with the error: host mode networking is not supported, and this message is now localized.

PR Checklist

  • 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

  • Added validation so if any --network value is host, command execution fails with:
    • host mode networking is not supported
  • Localized the host-mode rejection error by replacing the hardcoded exception text with a localization resource string.
  • Updated existing E2E tests for container create and container run host-mode cases to expect failure.
  • Added an E2E test to verify host-mode is rejected when multiple --network options are provided and one of them is host.
  • Ran clang-format on modified files.

Validation Steps Performed

  • Ran clang-format -i on changed files.
  • Verified formatting with clang-format --dry-run --style=file on changed files.
  • Ran python3 tools/devops/validate-localization.py.
  • Ran final validation tooling: code review returned no comments; CodeQL timed out in this sandbox run.
  • Attempted environment validation commands available in this sandbox; full Windows build/test execution was not available in this environment.

Copilot AI review requested due to automatic review settings June 5, 2026 20:33
@AmelBawa-msft AmelBawa-msft requested a review from a team as a code owner June 5, 2026 20:33
@AmelBawa-msft AmelBawa-msft marked this pull request as draft June 5, 2026 20:33
Copy link
Copy Markdown
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 --network support to the WSLC container run and container create commands, allowing users to attach containers to one or more networks by flowing the option through CLI parsing, validation, task option mapping, and container launch.

Changes:

  • Add --network as a repeatable CLI option for container run/create, validate non-empty values, and localize new help/error strings.
  • Extend container options/model + task parsing to carry a list of networks and apply them at container creation (primary network + additional networks).
  • Add unit + E2E coverage for default network behavior, host mode, user-defined networks, and rejected inputs.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/windows/wslc/WSLCCLIExecutionUnitTests.cpp Adds unit tests validating --network parsing and that options populate correctly.
test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp Adds E2E coverage for default/host/user-defined networks and input rejection for container run.
test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp Updates expected help text to include --network for container create.
src/windows/wslc/tasks/ContainerTasks.cpp Maps parsed --network args into ContainerOptions.Networks.
src/windows/wslc/services/ContainerService.cpp Applies selected networks when launching containers (primary mode + additional networks).
src/windows/wslc/services/ContainerModel.h Extends ContainerOptions with a Networks vector.
src/windows/wslc/commands/ContainerRunCommand.cpp Registers --network as a repeatable argument for container run.
src/windows/wslc/commands/ContainerCreateCommand.cpp Registers --network as a repeatable argument for container create.
src/windows/wslc/arguments/ArgumentValidation.cpp Adds validation rejecting empty/whitespace --network values; localizes workdir empty error.
src/windows/wslc/arguments/ArgumentDefinitions.h Adds Network argument definition wired to localized description.
localization/strings/en-US/Resources.resw Adds localized --network description + network/workdir empty error strings.

Comment thread src/windows/wslc/services/ContainerService.cpp Outdated
Copilot AI review requested due to automatic review settings June 5, 2026 21:16
@AmelBawa-msft AmelBawa-msft marked this pull request as ready for review June 5, 2026 21:16
Copy link
Copy Markdown
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Comment thread test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp
Copilot AI changed the title Add --network option to container create/run Add --network option to container create/run (excluding host mode) Jun 6, 2026
@AmelBawa-msft AmelBawa-msft requested a review from OneBlue June 6, 2026 00:25
Comment thread src/windows/wslc/arguments/ArgumentValidation.cpp Outdated
Copilot AI review requested due to automatic review settings June 6, 2026 00:31
@AmelBawa-msft AmelBawa-msft review requested due to automatic review settings June 6, 2026 00:31
@AmelBawa-msft AmelBawa-msft requested a review from OneBlue June 6, 2026 01:27
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.

4 participants